Skip to content

Instantly share code, notes, and snippets.

@junibrosas
Last active November 22, 2019 08:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save junibrosas/cb67c24791646e9c7203151347c72983 to your computer and use it in GitHub Desktop.
Save junibrosas/cb67c24791646e9c7203151347c72983 to your computer and use it in GitHub Desktop.
Anything momentJS
// a few seconds ago
moment.fn.fromNowOrNow = function (a) {
if (Math.abs(moment().diff(this)) < 25000) { // 25 seconds before or after now
return 'just now';
}
return this.fromNow(a);
}
// check expiry
const isExpired = moment().isAfter(activity.endDate);
// Find upcoming documents between start date and end date
.find({
$and: [
{ startDate: { $lte: new Date() } },
{ endDate: { $gte: new Date() } },
]
})
// formats
// 'MMMM Do YYYY' - January 26th 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment