test.equal(moment.duration({days: 25}).humanize(), "25 days", "25 days = 25 days");
test.equal(moment.duration({days: 26}).humanize(), "a month", "26 days = a month");
test.equal(moment.duration({days: 30}).humanize(), "a month", "30 days = a month");
- test.equal(moment.duration({days: 45}).humanize(), "2 months", "45 days = 2 months");
+ test.equal(moment.duration({days: 45}).humanize(), "a month", "45 days = a month");
test.equal(moment.duration({days: 46}).humanize(), "2 months", "46 days = 2 months");
- test.equal(moment.duration({days: 74}).humanize(), "2 months", "75 days = 2 months");
- test.equal(moment.duration({days: 76}).humanize(), "3 months", "76 days = 3 months");
+ test.equal(moment.duration({days: 74}).humanize(), "2 months", "74 days = 2 months");
+ test.equal(moment.duration({days: 77}).humanize(), "3 months", "77 days = 3 months");
test.equal(moment.duration({months: 1}).humanize(), "a month", "1 month = a month");
test.equal(moment.duration({months: 5}).humanize(), "5 months", "5 months = 5 months");
test.equal(moment.duration({days: 344}).humanize(), "a year", "344 days = a year");
});
test.expect(8);
+ // These are of course very fragile. Their existence merely hints that
+ // changing the way 'as' works changes the output.
test.equal(d.asYears().toFixed(2), "2.29", "years");
- test.equal(d.asMonths().toFixed(2), "27.51", "months");
- test.equal(d.asWeeks().toFixed(2), "119.33", "weeks");
- test.equal(d.asDays().toFixed(2), "835.34", "days");
- test.equal(d.asHours().toFixed(2), "20048.16", "hours");
- test.equal(d.asMinutes().toFixed(2), "1202889.33", "minutes");
- test.equal(d.asSeconds().toFixed(2), "72173360.01", "seconds");
- test.equal(d.asMilliseconds(), 72173360012, "milliseconds");
+ test.equal(d.asMonths().toFixed(2), "27.50", "months");
+ test.equal(d.asWeeks().toFixed(2), "119.59", "weeks");
+ test.equal(d.asDays().toFixed(2), "837.14", "days");
+ test.equal(d.asHours().toFixed(2), "20091.25", "hours");
+ test.equal(d.asMinutes().toFixed(2), "1205475.03", "minutes");
+ test.equal(d.asSeconds().toFixed(2), "72328502.01", "seconds");
+ test.equal(d.asMilliseconds(), 72328502012, "milliseconds");
test.done();
},
milliseconds: 12
});
+ // These are of course very fragile. Their existence merely hints that
+ // changing the way 'as' works changes the output.
test.expect(24);
test.equal(d.as("years").toFixed(2), "2.29", "years");
test.equal(d.as("year").toFixed(2), "2.29", "years = year");
test.equal(d.as("y").toFixed(2), "2.29", "years = y");
- test.equal(d.as("months").toFixed(2), "27.51", "months");
- test.equal(d.as("month").toFixed(2), "27.51", "months = month");
- test.equal(d.as("M").toFixed(2), "27.51", "months = M");
- test.equal(d.as("weeks").toFixed(2), "119.33", "weeks");
- test.equal(d.as("week").toFixed(2), "119.33", "weeks = week");
- test.equal(d.as("w").toFixed(2), "119.33", "weeks = w");
- test.equal(d.as("days").toFixed(2), "835.34", "days");
- test.equal(d.as("day").toFixed(2), "835.34", "days = day");
- test.equal(d.as("d").toFixed(2), "835.34", "days = d");
- test.equal(d.as("hours").toFixed(2), "20048.16", "hours");
- test.equal(d.as("hour").toFixed(2), "20048.16", "hours = hour");
- test.equal(d.as("h").toFixed(2), "20048.16", "hours = h");
- test.equal(d.as("minutes").toFixed(2), "1202889.33", "minutes");
- test.equal(d.as("minute").toFixed(2), "1202889.33", "minutes = minute");
- test.equal(d.as("m").toFixed(2), "1202889.33", "minutes = m");
- test.equal(d.as("seconds").toFixed(2), "72173360.01", "seconds");
- test.equal(d.as("second").toFixed(2), "72173360.01", "seconds = second");
- test.equal(d.as("s").toFixed(2), "72173360.01", "seconds = s");
- test.equal(d.as("milliseconds"), 72173360012, "milliseconds");
- test.equal(d.as("millisecond"), 72173360012, "milliseconds = millisecond");
- test.equal(d.as("ms"), 72173360012, "milliseconds = ms");
+ test.equal(d.as("months").toFixed(2), "27.50", "months");
+ test.equal(d.as("month").toFixed(2), "27.50", "months = month");
+ test.equal(d.as("M").toFixed(2), "27.50", "months = M");
+ test.equal(d.as("weeks").toFixed(2), "119.59", "weeks");
+ test.equal(d.as("week").toFixed(2), "119.59", "weeks = week");
+ test.equal(d.as("w").toFixed(2), "119.59", "weeks = w");
+ test.equal(d.as("days").toFixed(2), "837.14", "days");
+ test.equal(d.as("day").toFixed(2), "837.14", "days = day");
+ test.equal(d.as("d").toFixed(2), "837.14", "days = d");
+ test.equal(d.as("hours").toFixed(2), "20091.25", "hours");
+ test.equal(d.as("hour").toFixed(2), "20091.25", "hours = hour");
+ test.equal(d.as("h").toFixed(2), "20091.25", "hours = h");
+ test.equal(d.as("minutes").toFixed(2), "1205475.03", "minutes");
+ test.equal(d.as("minute").toFixed(2), "1205475.03", "minutes = minute");
+ test.equal(d.as("m").toFixed(2), "1205475.03", "minutes = m");
+ test.equal(d.as("seconds").toFixed(2), "72328502.01", "seconds");
+ test.equal(d.as("second").toFixed(2), "72328502.01", "seconds = second");
+ test.equal(d.as("s").toFixed(2), "72328502.01", "seconds = s");
+ test.equal(d.as("milliseconds"), 72328502012, "milliseconds");
+ test.equal(d.as("millisecond"), 72328502012, "milliseconds = millisecond");
+ test.equal(d.as("ms"), 72328502012, "milliseconds = ms");
test.done();
},
test.equal(start.from(moment([2007, 1, 28]).subtract({d: 26})), "in a month", "26 days = a month");
test.equal(start.from(moment([2007, 1, 28]).subtract({d: 30})), "in a month", "30 days = a month");
test.equal(start.from(moment([2007, 1, 28]).subtract({d: 45})), "in a month", "45 days = a month");
- test.equal(start.from(moment([2007, 1, 28]).subtract({d: 46})), "in 2 months", "46 days = 2 months");
- test.equal(start.from(moment([2007, 1, 28]).subtract({d: 74})), "in 2 months", "75 days = 2 months");
- test.equal(start.from(moment([2007, 1, 28]).subtract({d: 76})), "in 3 months", "76 days = 3 months");
+ test.equal(start.from(moment([2007, 1, 28]).subtract({d: 47})), "in 2 months", "47 days = 2 months");
+ test.equal(start.from(moment([2007, 1, 28]).subtract({d: 74})), "in 2 months", "74 days = 2 months");
+ test.equal(start.from(moment([2007, 1, 28]).subtract({d: 78})), "in 3 months", "78 days = 3 months");
test.equal(start.from(moment([2007, 1, 28]).subtract({M: 1})), "in a month", "1 month = a month");
test.equal(start.from(moment([2007, 1, 28]).subtract({M: 5})), "in 5 months", "5 months = 5 months");
- test.equal(start.from(moment([2007, 1, 28]).subtract({d: 344})), "in 11 months", "344 days = 11 months");
+ test.equal(start.from(moment([2007, 1, 28]).subtract({d: 315})), "in 10 months", "315 days = 10 months");
+ test.equal(start.from(moment([2007, 1, 28]).subtract({d: 344})), "in a year", "344 days = a year");
test.equal(start.from(moment([2007, 1, 28]).subtract({d: 345})), "in a year", "345 days = a year");
- test.equal(start.from(moment([2007, 1, 28]).subtract({d: 547})), "in a year", "547 days = a year");
- test.equal(start.from(moment([2007, 1, 28]).subtract({d: 548})), "in a year", "548 days = a year");
+ test.equal(start.from(moment([2007, 1, 28]).subtract({d: 548})), "in 2 years", "548 days = in 2 years");
test.equal(start.from(moment([2007, 1, 28]).subtract({y: 1})), "in a year", "1 year = a year");
test.equal(start.from(moment([2007, 1, 28]).subtract({y: 5})), "in 5 years", "5 years = 5 years");
test.equal(start.from(moment([2007, 1, 28]).add({d: 25})), "25 days ago", "25 days = 25 days");
test.equal(start.from(moment([2007, 1, 28]).add({d: 26})), "a month ago", "26 days = a month");
test.equal(start.from(moment([2007, 1, 28]).add({d: 30})), "a month ago", "30 days = a month");
- test.equal(start.from(moment([2007, 1, 28]).add({d: 45})), "2 months ago", "45 days = 2 months");
+ test.equal(start.from(moment([2007, 1, 28]).add({d: 43})), "a month ago", "43 days = a month");
test.equal(start.from(moment([2007, 1, 28]).add({d: 46})), "2 months ago", "46 days = 2 months");
test.equal(start.from(moment([2007, 1, 28]).add({d: 74})), "2 months ago", "75 days = 2 months");
test.equal(start.from(moment([2007, 1, 28]).add({d: 76})), "3 months ago", "76 days = 3 months");
test.equal(start.from(moment([2007, 1, 28]).add({M: 1})), "a month ago", "1 month = a month");
test.equal(start.from(moment([2007, 1, 28]).add({M: 5})), "5 months ago", "5 months = 5 months");
- test.equal(start.from(moment([2007, 1, 28]).add({d: 344})), "11 months ago", "344 days = 11 months");
+ test.equal(start.from(moment([2007, 1, 28]).add({d: 315})), "10 months ago", "315 days = 10 months");
+ test.equal(start.from(moment([2007, 1, 28]).add({d: 344})), "a year ago", "344 days = a year");
test.equal(start.from(moment([2007, 1, 28]).add({d: 345})), "a year ago", "345 days = a year");
- test.equal(start.from(moment([2007, 1, 28]).add({d: 547})), "a year ago", "547 days = a year");
- test.equal(start.from(moment([2007, 1, 28]).add({d: 548})), "a year ago", "548 days = a year");
+ test.equal(start.from(moment([2007, 1, 28]).add({d: 548})), "2 years ago", "548 days = 2 years");
test.equal(start.from(moment([2007, 1, 28]).add({y: 1})), "a year ago", "1 year = a year");
test.equal(start.from(moment([2007, 1, 28]).add({y: 5})), "5 years ago", "5 years = 5 years");
var moment = require("../../moment");
exports.relativeTime = {
- setUp : function (done) {
- done();
- },
-
"default thresholds" : function (test) {
- test.expect(12);
-
var a = moment();
// Seconds to minutes threshold
a.subtract('hours', 1);
test.equal(a.fromNow(), "a day ago", "Above default hours to day threshold");
- // Days to month (singular) threshold
+ // Days to month threshold
a = moment();
a.subtract('days', 25);
test.equal(a.fromNow(), "25 days ago", "Below default days to month (singular) threshold");
a.subtract('days', 1);
test.equal(a.fromNow(), "a month ago", "Above default days to month (singular) threshold");
- // Days to months (plural) threshold
+ // months to year threshold
a = moment();
- a.subtract('days', 45);
- test.equal(a.fromNow(), "a month ago", "Below default days to months (plural) threshold");
- a.subtract('days', 1);
- test.equal(a.fromNow(), "2 months ago", "Above default days to months (plural) threshold");
-
- // Days to years threshold
- a = moment();
- a.subtract('days', 344);
- test.equal(a.fromNow(), "11 months ago", "Below default days to years threshold");
- a.subtract('days', 1);
+ a.subtract(10, 'months');
+ test.equal(a.fromNow(), "10 months ago", "Below default days to years threshold");
+ a.subtract(1, 'month');
test.equal(a.fromNow(), "a year ago", "Above default days to years threshold");
test.done();
},
"custom thresholds" : function (test) {
- test.expect(12);
-
// Seconds to minutes threshold
moment.relativeTimeThreshold('s', 55);
+
var a = moment();
a.subtract('seconds', 54);
test.equal(a.fromNow(), "a few seconds ago", "Below custom seconds to minutes threshold");
test.equal(a.fromNow(), "a day ago", "Above custom hours to days threshold");
moment.relativeTimeThreshold('h', 22);
- // Days to month (singluar) threshold
- moment.relativeTimeThreshold('dd', 28);
+ // Days to month threshold
+ moment.relativeTimeThreshold('d', 28);
a = moment();
- a.subtract('days', 28);
- test.equal(a.fromNow(), "28 days ago", "Below custom days to month (singular) threshold");
+ a.subtract('days', 27);
+ test.equal(a.fromNow(), "27 days ago", "Below custom days to month (singular) threshold");
a.subtract('days', 1);
test.equal(a.fromNow(), "a month ago", "Above custom days to month (singular) threshold");
- moment.relativeTimeThreshold('dd', 25);
-
- // Days to months (plural) threshold
- moment.relativeTimeThreshold('dm', 55);
- a = moment();
- a.subtract('days', 55);
- test.equal(a.fromNow(), "a month ago", "Above custom days to months (plural) threshold");
- a.subtract('days', 1);
- test.equal(a.fromNow(), "2 months ago", "Below custom days to months (plural) threshold");
- moment.relativeTimeThreshold('dm', 45);
+ moment.relativeTimeThreshold('d', 26);
- // Days to years threshold
- moment.relativeTimeThreshold('dy', 360);
+ // months to years threshold
+ moment.relativeTimeThreshold('M', 9);
a = moment();
- a.subtract('days', 359);
- test.equal(a.fromNow(), "12 months ago", "Below custom days to years threshold");
- a.subtract('days', 1);
+ a.subtract('months', 8);
+ test.equal(a.fromNow(), "8 months ago", "Below custom days to years threshold");
+ a.subtract('months', 1);
test.equal(a.fromNow(), "a year ago", "Above custom days to years threshold");
- moment.relativeTimeThreshold('dy', 345);
+ moment.relativeTimeThreshold('M', 11);
test.done();
}
};