<commit_before>import moment from 'moment';

export const STORY_PUB_DATE_UNDATEABLE = 'undateable';

const SOLR_DATE_FORMAT = 'YYYY-MM-DDTHH:mm:ssZ';

const SHORT_SOLR_DATE_FORMAT = 'YYYY-MM-DD';

const SHORT_VIS_FORMAT = 'MM/DD';

const GAP_DATE_FORMAT = 'YYYY-MM-DD HH:mm:ssZ';

const DB_DATE_FORMAT = 'YYYY-MM-DD HH:mm:ss';

const JOB_STATUS_DATE_FORMAT = 'YYYY-MM-DD HH:mm:ss';

const TOPIC_DATE_FORMAT = 'YYYY-MM-DD';

// "2017-04-13 12:26:59.649513"
const SNAPSHOT_DATE_FORMAT = 'YYYY-MM-DD HH:mm:ss.SSSSSS';


export const ONE_DAY_RANGE = '+1DAY';

export const PAST_WEEK = 'week';
export const PAST_TWO_WEEKS = 'two_weeks';
export const PAST_MONTH = 'month';
export const PAST_YEAR = 'year';
export const PAST_ALL = 'all-time';

export function getCurrentDate() {
  const testdate = moment().format(TOPIC_DATE_FORMAT);
  return testdate;
}

export function getVisDate(dateString) {
  return moment(dateString).format(SHORT_VIS_FORMAT);
}

export function getShortDate(dateString) {
  return moment(dateString).format('ll');
}

export function getDateFromTimestamp(milliseconds) {
  return moment.utc(parseInt(milliseconds, 10)).toDate();
}

export function isStartDateAfterEndDate(start, end) {
  return moment(start).isAfter(end);
}

export function oneWeekLater(date) {
  const weekLater = moment(date).add(1, 'week');
  return weekLater;
}

export function oneDayLater(date) {
  const dayLater = moment(date).add(1, 'day');
  return dayLater;
}

export function oneMonthBefore(date) {
  const monthBefore = moment(date).subtract(1, 'month').format(TOPIC_DATE_FORMAT);
  return monthBefore;
}

export function isMoreThanAYearInPast(dateInPast) {
  const yearPriorToNow = moment().subtract(1, 'years');
  return yearPriorToNow.isAfter(dateInPast);
}

export function isADayDifference(date0, date1) {
  const firstDate = moment(date0);
  const oneDayAfter = firstDate.add(1, 'days');
  return oneDayAfter.isAfter(moment(date1));
}

export function parseSolrShortDate(dateStr) {
  return moment(dateStr, SHORT_SOLR_DATE_FORMAT).toDate();
}

export function isValidSolrDate(dateStr) {
  return moment(dateStr, SHORT_SOLR_DATE_FORMAT).isValid();
}

export function solrFormat(date, short = true) {
  return moment(date).format(short ? SHORT_SOLR_DATE_FORMAT : SOLR_DATE_FORMAT);
}

export function solrTimestamp(date) {
  return moment(date).format('x');
}

export function getMomentDateSubtraction(date, num, timeUnit) {
  return moment(date).subtract(num, timeUnit).format(TOPIC_DATE_FORMAT);
}

export function topicDateToMoment(topicDate, strict = true) {
  return moment(topicDate, TOPIC_DATE_FORMAT, strict);
}

export function snapshotDateToMoment(snapshotDateStr, strict = false) {
  return moment(snapshotDateStr, SNAPSHOT_DATE_FORMAT, strict);
}

export function jobStatusDateToMoment(statusDate, strict = true) {
  return moment(statusDate, JOB_STATUS_DATE_FORMAT, strict);
}

export function healthStartDateToMoment(healthStartDate, strict = true) {
  return moment(healthStartDate.substring(0, DB_DATE_FORMAT.length), DB_DATE_FORMAT, strict);
}

export function sourceSuggestionDateToMoment(suggestionDate, strict = true) {
  return moment(suggestionDate.substring(0, DB_DATE_FORMAT.length), DB_DATE_FORMAT, strict);
}

export function solrDateToMoment(solrDateString, strict = true) {
  return moment(solrDateString, SOLR_DATE_FORMAT, strict);
}

export function storyPubDateToMoment(solrDateString, strict = true) {
  return moment(solrDateString, DB_DATE_FORMAT, strict);
}

export function storyPubDateToTimestamp(solrDateString, strict = true) {
  return storyPubDateToMoment(solrDateString, strict).valueOf();
}

function gapDateToMomemt(gapDateString, strict = true) {
  return moment(gapDateString, GAP_DATE_FORMAT, strict);
}


// Helper to change solr dates (2015-12-14T00:00:00Z) into javascript date ojects
export function calcStories(countsMap) {
  let storyCount = 0;
  Object.keys(countsMap).forEach((k) => {
    const v = countsMap[k];<commit_msg>parse date without fractional seconds (#1212)<commit_after>import moment from 'moment';

export const STORY_PUB_DATE_UNDATEABLE = 'undateable';

const SOLR_DATE_FORMAT = 'YYYY-MM-DDTHH:mm:ssZ';

const SHORT_SOLR_DATE_FORMAT = 'YYYY-MM-DD';

const SHORT_VIS_FORMAT = 'MM/DD';

const GAP_DATE_FORMAT = 'YYYY-MM-DD HH:mm:ssZ';

const DB_DATE_FORMAT = 'YYYY-MM-DD HH:mm:ss';

const JOB_STATUS_DATE_FORMAT = 'YYYY-MM-DD HH:mm:ss';

const TOPIC_DATE_FORMAT = 'YYYY-MM-DD';

// "2017-04-13 12:26:59.649513"
const SNAPSHOT_DATE_FORMAT = 'YYYY-MM-DD HH:mm:ss.SSSSSS';


export const ONE_DAY_RANGE = '+1DAY';

export const PAST_WEEK = 'week';
export const PAST_TWO_WEEKS = 'two_weeks';
export const PAST_MONTH = 'month';
export const PAST_YEAR = 'year';
export const PAST_ALL = 'all-time';

export function getCurrentDate() {
  const testdate = moment().format(TOPIC_DATE_FORMAT);
  return testdate;
}

export function getVisDate(dateString) {
  return moment(dateString).format(SHORT_VIS_FORMAT);
}

export function getShortDate(dateString) {
  return moment(dateString).format('ll');
}

export function getDateFromTimestamp(milliseconds) {
  return moment.utc(parseInt(milliseconds, 10)).toDate();
}

export function isStartDateAfterEndDate(start, end) {
  return moment(start).isAfter(end);
}

export function oneWeekLater(date) {
  const weekLater = moment(date).add(1, 'week');
  return weekLater;
}

export function oneDayLater(date) {
  const dayLater = moment(date).add(1, 'day');
  return dayLater;
}

export function oneMonthBefore(date) {
  const monthBefore = moment(date).subtract(1, 'month').format(TOPIC_DATE_FORMAT);
  return monthBefore;
}

export function isMoreThanAYearInPast(dateInPast) {
  const yearPriorToNow = moment().subtract(1, 'years');
  return yearPriorToNow.isAfter(dateInPast);
}

export function isADayDifference(date0, date1) {
  const firstDate = moment(date0);
  const oneDayAfter = firstDate.add(1, 'days');
  return oneDayAfter.isAfter(moment(date1));
}

export function parseSolrShortDate(dateStr) {
  return moment(dateStr, SHORT_SOLR_DATE_FORMAT).toDate();
}

export function isValidSolrDate(dateStr) {
  return moment(dateStr, SHORT_SOLR_DATE_FORMAT).isValid();
}

export function solrFormat(date, short = true) {
  return moment(date).format(short ? SHORT_SOLR_DATE_FORMAT : SOLR_DATE_FORMAT);
}

export function solrTimestamp(date) {
  return moment(date).format('x');
}

export function getMomentDateSubtraction(date, num, timeUnit) {
  return moment(date).subtract(num, timeUnit).format(TOPIC_DATE_FORMAT);
}

export function topicDateToMoment(topicDate, strict = true) {
  return moment(topicDate, TOPIC_DATE_FORMAT, strict);
}

export function snapshotDateToMoment(snapshotDateStr, strict = false) {
  return moment(snapshotDateStr, SNAPSHOT_DATE_FORMAT, strict);
}

export function jobStatusDateToMoment(statusDate, strict = true) {
  return moment(statusDate, JOB_STATUS_DATE_FORMAT, strict);
}

export function healthStartDateToMoment(healthStartDate, strict = true) {
  return moment(healthStartDate.substring(0, DB_DATE_FORMAT.length), DB_DATE_FORMAT, strict);
}

export function sourceSuggestionDateToMoment(suggestionDate, strict = true) {
  return moment(suggestionDate.substring(0, DB_DATE_FORMAT.length), DB_DATE_FORMAT, strict);
}

export function solrDateToMoment(solrDateString, strict = true) {
  return moment(solrDateString, SOLR_DATE_FORMAT, strict);
}

export function storyPubDateToMoment(solrDateString, strict = true) {
  // need to trim date here because sometimes it has fractional seconds as a decimal and the
  // intl helper can't format this
  return moment(solrDateString.substring(0, 19), DB_DATE_FORMAT, strict);
}

export function storyPubDateToTimestamp(solrDateString, strict = true) {
  return storyPubDateToMoment(solrDateString, strict).valueOf();
}

function gapDateToMomemt(gapDateString, strict = true) {
  return moment(gapDateString, GAP_DATE_FORMAT, strict);
}


// Helper to change solr dates (2015-12-14T00:00:00Z) into javascript date ojects
export function calcStories(countsMap) {
  let storyCount = 0;
  Object.keys(countsMap).forEach((k) => {
    const v = countsMap[k];
{'fraction_non_alphanumeric': 0.11279026907482492, 'fraction_numerical': 0.012900847769996313, 'mean_word_length': 6.474747474747475, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1833381', 'n_tokens_mistral': 2874, 'n_tokens_neox': 2750, 'n_words': 578}