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
Another thing along those lines, what about changing the formatting strings to be true formatting strings, instead of
moment.fn.from
like replacement patterns. Heres an example:Those escape characters are pretty ugly though, so maybe I should also introduce an escape opening and closing bracket notation like this:
Doing this would also future proof against added formatting tokens.