Skip to content

Instantly share code, notes, and snippets.

View frama21's full-sized avatar

Fajar Ramdani A frama21

  • Bandung, Indonesia
  • 15:01 (UTC +07:00)
  • LinkedIn in/frama21
View GitHub Profile
@davidrleonard
davidrleonard / from-now.js
Last active February 18, 2024 11:23
moment.fromNow() implemented in vanilla JavaScript as a simple, standalone function. Runs in the browser. No dependencies required.
/**
* Implements all the behaviors of moment.fromNow(). Pass a
* valid JavaScript Date object and the method will return the
* time that has passed since that date in a human-readable
* format. Passes the moment test suite for `fromNow()`.
* See: https://momentjs.com/docs/#/displaying/fromnow/
*
* @example
*
* var pastDate = new Date('2017-10-01T02:30');