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
I cleaned up the spec a little bit, mostly conforming to the code you are working on.
One thing that should probably be added is
relativeDate.else
instead of hard-coding 'L' as the format for everything else. This way, if someone wants to change the way other dates are presented, they won't have to hack the library, they can just make their own lang file with their preferences.