]> git.ipfire.org Git - thirdparty/moment.git/commitdiff
Revert "Merge pull request #4910 from nanomosfet:add-weeks-to-relative"
authorIskren Chernev <iskren.chernev@gmail.com>
Sat, 25 Apr 2020 21:42:34 +0000 (00:42 +0300)
committerIskren Chernev <iskren.chernev@gmail.com>
Sat, 25 Apr 2020 21:42:34 +0000 (00:42 +0300)
This reverts commit 9bd2dc74209ec21c327aa2af6620e3d2dd3ae4b6, reversing
changes made to ed6fd040527d0a81b86695f898ac0b6e6f479295.

src/lib/duration/duration.js
src/lib/duration/humanize.js
src/lib/locale/relative.js
src/moment.js
src/test/moment/relative_time.js

index 27acf6985a5dc251ec6e2f1ab31c98f1ab9d1e8e..528b568121fbd4a98a270ae8fd54bd738ece2aa1 100644 (file)
@@ -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
 };
index 8227bd7f0baf5e29607a75a57e12db204aedd995..454b01ae516b7d1b12eb40e5bc2a7c66a2c0a02e 100644 (file)
@@ -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();
     }
index e9560a405be1b3b87961f453ce11439f8a947a3f..431466b2da5a04c8668ba365605e139d423f54b6 100644 (file)
@@ -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',
index b9dd37c22f8a585c250e084ac3a528a7d1f2b4d8..14e64e93de19af47c8ed2e7499b134b1e3c5fa00 100644 (file)
@@ -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 = {
index 7d69284fbb4bb0a2d3fde4cb783ecf5b9566c663..f1ea491cb0f4d44ecfce860d491b9af38a6be707 100644 (file)
@@ -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);