Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Possible addition to moment.js
// We assume it's Friday, December 2nd, 2 PM
// This could be interesting for a listing of events in a calendar.
// Two Questions:
// 1. How would you call the function?
// 2. What would you return for the dates in 1 and 2 weeks?
moment().xxx() // "Today at 2 PM"
moment().add('hours', 1).xxx() // "Today at 3 PM"
moment().add('days', 1).xxx() // "Tomorrow at 2 PM"
moment().add('days', 2).xxx() // "Sunday at 2 PM"
moment().add('weeks', 1).xxx() // What do you think ???
moment().add('weeks', 2).xxx() // 12/16/2011 What do you think ???
moment().subtract('hours', 1).xxx() // "Today at 1 PM"
moment().subtract('days', 1).xxx() // "Yesterday at 2 PM"
moment().subtract('days', 2).xxx() // "Wednesday at 2 PM"
moment().subtract('weeks', 1).xxx() // What do you think ???
moment().subtract('weeks', 2).xxx() // 11/18/2011 What do you think ???
@timrwood
Copy link

timrwood commented Dec 2, 2011

I'm thinking of adding something similar as well. Couldn't think of a name though either...

https://gist.github.com/1280098

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment