Getting Relative Time in the Date Plugin

There was one missing functionality in the Date Plugin, which is an ability to get relative times which you can do by passing the parameters into the function in the Moment.js library. But it looks like you can’t do that in the plugin itself, which is simply a part of writing mistake in the plugin’s source.

I see in the source you can actually pass some arguments into the plugin, and it should iterate those arguments into the moment() function instead like this:


<span style="color:#323232;">  if(!window._alreadyLoadedDatePluginCode8934792) {
</span><span style="color:#323232;">    loadPluginCode();
</span><span style="color:#323232;">    window._alreadyLoadedDatePluginCode8934792 = true;
</span><span style="color:#323232;">  }
</span><span style="color:#323232;">  return moment(...args);
</span>

So now, getting relative times directly from the date plugin should work, just like what you would in the original Moment.js library. And there should also be a documentation somewhere in the plugin page.

BluePower,
@BluePower@sh.itjust.works avatar

Here’s my temporary fork of the plugin that can actually accept arguments, while the change hasn’t been made to the official yet:

perchance.org/vkauhn2zdw#edit

VioneT,
@VioneT@lemmy.world avatar

And there should also be a documentation somewhere in the plugin page.

There is a link to the Moment.js website on the notes.

But yeah, relative dates via date(‘20121212’, ‘YYYYMMDD’) doesn’t work with the current one.

BluePower,
@BluePower@sh.itjust.works avatar
  • All
  • Subscribed
  • Moderated
  • Favorites
  • perchance@lemmy.world
  • ethstaker
  • DreamBathrooms
  • InstantRegret
  • magazineikmin
  • ngwrru68w68
  • cubers
  • thenastyranch
  • Youngstown
  • rosin
  • slotface
  • cisconetworking
  • mdbf
  • kavyap
  • Durango
  • megavids
  • khanakhh
  • GTA5RPClips
  • anitta
  • osvaldo12
  • everett
  • normalnudes
  • tester
  • tacticalgear
  • provamag3
  • modclub
  • Leos
  • JUstTest
  • lostlight
  • All magazines