Show the date with the smallest order of magnitude of difference from now.
closest
calendar
magnitude
relativeDate
moment.relativeDate.today = "Today at %t";
moment().closest() // Today at 1pm
moment().add('hours', 1).closest() // Today at 2pm
moment.relativeDate.tomorrow = "Tomorrow at %t";
moment().subtract('days', 1).closest() // Tomorrow at 1pm
moment.relativeDate.yesterday = "Yesterday at %t";
moment().subtract('days', 1).closest() // Yesterday at 1pm
moment.relativeDate.last = "Last %d at %t";
moment.relativeDate.yesterday = "Next %d at %t";
moment().subtract('days', 7).closest() // Last Sunday at 1pm
moment().subtract('days', 6).closest() // Last Saturday at 1pm
moment().add('days', 6).closest() // Next Saturday at 1pm
moment().add('days', 7).closest() // Next Sunday at 1pm
moment.relativeDate.else = "L"; // a formatting string
moment().add('weeks', 2).closest() // 7/10/1986
Good specification.
We started to implement it, using the following function name: relativeDate().
You can follow progression here: https://github.com/caillou/moment/commits/relative-date
We'll finish it this weekend.