From: Iskren Chernev Date: Sat, 25 Apr 2020 21:42:34 +0000 (+0300) Subject: Revert "Merge pull request #4910 from nanomosfet:add-weeks-to-relative" X-Git-Tag: 2.25.0~38 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8058876de269cafb63dc6fb18566a13fcaeeb6b8;p=thirdparty%2Fmoment.git Revert "Merge pull request #4910 from nanomosfet:add-weeks-to-relative" This reverts commit 9bd2dc74209ec21c327aa2af6620e3d2dd3ae4b6, reversing changes made to ed6fd040527d0a81b86695f898ac0b6e6f479295. --- diff --git a/src/lib/duration/duration.js b/src/lib/duration/duration.js index 27acf6985..528b56812 100644 --- a/src/lib/duration/duration.js +++ b/src/lib/duration/duration.js @@ -5,14 +5,12 @@ import { createDuration } from './create'; import { isDuration } from './constructor'; import { getSetRelativeTimeRounding, - getSetRelativeTimeThreshold, - getSetRelativeTimeIncludeWeeks + getSetRelativeTimeThreshold } from './humanize'; export { createDuration, isDuration, getSetRelativeTimeRounding, - getSetRelativeTimeThreshold, - getSetRelativeTimeIncludeWeeks + getSetRelativeTimeThreshold }; diff --git a/src/lib/duration/humanize.js b/src/lib/duration/humanize.js index 8227bd7f0..454b01ae5 100644 --- a/src/lib/duration/humanize.js +++ b/src/lib/duration/humanize.js @@ -1,33 +1,28 @@ import { createDuration } from './create'; var round = Math.round; - var thresholds = { ss: 44, // a few seconds to seconds s : 45, // seconds to minute m : 45, // minutes to hour h : 22, // hours to day - d : 26, // days to week/month - w : 4, // weeks to months + d : 26, // days to month M : 11 // months to year }; -var includeWeeks = false; - // helper function for moment.fn.from, moment.fn.fromNow, and moment.duration.fn.humanize function substituteTimeAgo(string, number, withoutSuffix, isFuture, locale) { return locale.relativeTime(number || 1, !!withoutSuffix, string, isFuture); } function relativeTime (posNegDuration, withoutSuffix, locale) { - var duration = createDuration(posNegDuration).abs(); - var seconds = round(duration.as('s')); - var minutes = round(duration.as('m')); - var hours = round(duration.as('h')); - var days = round(duration.as('d')); - var weeks = round(duration.as('w')); - var months = round(duration.as('M')); - var years = round(duration.as('y')); + var duration = createDuration(posNegDuration).abs(); + var seconds = round(duration.as('s')); + var minutes = round(duration.as('m')); + var hours = round(duration.as('h')); + var days = round(duration.as('d')); + var months = round(duration.as('M')); + var years = round(duration.as('y')); var a = seconds <= thresholds.ss && ['s', seconds] || seconds < thresholds.s && ['ss', seconds] || @@ -36,15 +31,10 @@ function relativeTime (posNegDuration, withoutSuffix, locale) { hours <= 1 && ['h'] || hours < thresholds.h && ['hh', hours] || days <= 1 && ['d'] || - days < thresholds.d && ['dd', days]; - - if (includeWeeks) { - a = a || weeks <= 1 && ['w'] || - weeks < thresholds.w && ['ww', weeks]; - } - a = a || months <= 1 && ['M'] || - months < thresholds.M && ['MM', months] || - years <= 1 && ['y'] || ['yy', years]; + days < thresholds.d && ['dd', days] || + months <= 1 && ['M'] || + months < thresholds.M && ['MM', months] || + years <= 1 && ['y'] || ['yy', years]; a[2] = withoutSuffix; a[3] = +posNegDuration > 0; @@ -78,25 +68,8 @@ export function getSetRelativeTimeThreshold (threshold, limit) { } return true; } -export function getSetRelativeTimeIncludeWeeks(setIncludeWeeks) { - if (setIncludeWeeks === undefined) { - return includeWeeks; - } - if (typeof setIncludeWeeks !== 'boolean') { - return false; - } - includeWeeks = setIncludeWeeks; - if (includeWeeks === true) { - thresholds.w = 4; - thresholds.d = 7; - } - if (includeWeeks === false) { - delete thresholds.w; - thresholds.d = 26; - } - return true; -} -export function humanize (withSuffix, includeWeeks) { + +export function humanize (withSuffix) { if (!this.isValid()) { return this.localeData().invalidDate(); } diff --git a/src/lib/locale/relative.js b/src/lib/locale/relative.js index e9560a405..431466b2d 100644 --- a/src/lib/locale/relative.js +++ b/src/lib/locale/relative.js @@ -9,8 +9,6 @@ export var defaultRelativeTime = { hh : '%d hours', d : 'a day', dd : '%d days', - w : 'a week', - ww : '%d weeks', M : 'a month', MM : '%d months', y : 'a year', diff --git a/src/moment.js b/src/moment.js index b9dd37c22..14e64e93d 100644 --- a/src/moment.js +++ b/src/moment.js @@ -42,8 +42,7 @@ import { isDuration, createDuration as duration, getSetRelativeTimeRounding as relativeTimeRounding, - getSetRelativeTimeThreshold as relativeTimeThreshold, - getSetRelativeTimeIncludeWeeks as relativeTimeIncludeWeeks + getSetRelativeTimeThreshold as relativeTimeThreshold } from './lib/duration/duration'; import { normalizeUnits } from './lib/units/units'; @@ -52,34 +51,33 @@ import isDate from './lib/utils/is-date'; setHookCallback(local); -moment.fn = fn; -moment.min = min; -moment.max = max; -moment.now = now; -moment.utc = utc; -moment.unix = unix; -moment.months = months; -moment.isDate = isDate; -moment.locale = locale; -moment.invalid = invalid; -moment.duration = duration; -moment.isMoment = isMoment; -moment.weekdays = weekdays; -moment.parseZone = parseZone; -moment.localeData = localeData; -moment.isDuration = isDuration; -moment.monthsShort = monthsShort; -moment.weekdaysMin = weekdaysMin; -moment.defineLocale = defineLocale; -moment.updateLocale = updateLocale; -moment.locales = locales; -moment.weekdaysShort = weekdaysShort; -moment.normalizeUnits = normalizeUnits; -moment.relativeTimeRounding = relativeTimeRounding; -moment.relativeTimeThreshold = relativeTimeThreshold; -moment.relativeTimeIncludeWeeks = relativeTimeIncludeWeeks; -moment.calendarFormat = getCalendarFormat; -moment.prototype = fn; +moment.fn = fn; +moment.min = min; +moment.max = max; +moment.now = now; +moment.utc = utc; +moment.unix = unix; +moment.months = months; +moment.isDate = isDate; +moment.locale = locale; +moment.invalid = invalid; +moment.duration = duration; +moment.isMoment = isMoment; +moment.weekdays = weekdays; +moment.parseZone = parseZone; +moment.localeData = localeData; +moment.isDuration = isDuration; +moment.monthsShort = monthsShort; +moment.weekdaysMin = weekdaysMin; +moment.defineLocale = defineLocale; +moment.updateLocale = updateLocale; +moment.locales = locales; +moment.weekdaysShort = weekdaysShort; +moment.normalizeUnits = normalizeUnits; +moment.relativeTimeRounding = relativeTimeRounding; +moment.relativeTimeThreshold = relativeTimeThreshold; +moment.calendarFormat = getCalendarFormat; +moment.prototype = fn; // currently HTML5 input type only supports 24-hour formats moment.HTML5_FMT = { diff --git a/src/test/moment/relative_time.js b/src/test/moment/relative_time.js index 7d69284fb..f1ea491cb 100644 --- a/src/test/moment/relative_time.js +++ b/src/test/moment/relative_time.js @@ -82,23 +82,6 @@ test('default thresholds toNow', function (assert) { test('custom thresholds', function (assert) { var a; - // including weeks - moment.relativeTimeIncludeWeeks(true); - // threshold for days to weeks with including weeks - a = moment(); - a.subtract(6, 'days'); - assert.equal(a.fromNow(), '6 days ago', 'Below threshold days for weeks'); - a.subtract(1, 'days'); - assert.equal(a.fromNow(), 'a week ago', 'Above threshold days for weeks'); - - // threshold for days to weeks with including weeks - a = moment(); - a.subtract(3, 'weeks'); - assert.equal(a.fromNow(), '3 weeks ago', 'Below threshold weeks for months'); - a.subtract(1, 'week'); - assert.equal(a.fromNow(), 'a month ago', 'Above threshold weeks for months'); - moment.relativeTimeIncludeWeeks(false); - assert.equal(moment.relativeTimeIncludeWeeks(), false); // Seconds to minute threshold, under 30 moment.relativeTimeThreshold('s', 25);