// good-time.js by Gayan Sandamal // LinkedIn - https://www.linkedin.com/in/gayan-sandamal/
good-time.js will reduce your development time in getting time differences between two standard times.
-
import the goodTimeDiff method from good-time.js to your project import {goodTimeDiff} from './scripts/good-time.js'
-
declare an object to give settings like below. let settings = {}
-
now assign time values to the declared object variable. ***time must be in standard format and must be a string! ***'from' is optional the default value will be the browser current time. ***'prefix' and 'suffix' are optional.
let publishedTime = '2019-01-11T00:00:29.251Z' let settings = { 'from': '2019-01-13T00:00:29.251Z', 'to': publishedTime, 'prefix': 'Published', 'suffix': 'ago' }
-
now calllback the method called goodTimeDiff() and pass the settings object variable as a parameter. goodTimeDiff(settings)
-
Finally assign the method to any variable you want. let lastCommentedTime = goodTimeDiff(timeSettings)
-
Output will be like, Published 2 hours ago