timex icon indicating copy to clipboard operation
timex copied to clipboard

Relative/Calendar time formatters/parsers

Open bitwalker opened this issue 9 years ago • 12 comments

These two are common use cases for formatting dates/times, so I'd like to add them as part of Timex rather than relying on plugins for them.

  • [x] Relative time formatter
  • [ ] Calendar time formatter

Relative Time (based on Moment.js)

Range Key Sample Output
0 to 45 seconds s a few seconds ago
45 to 90 seconds m a minute ago
90 seconds to 45 minutes mm 2 minutes ago ... 45 minutes ago
45 to 90 minutes h an hour ago
90 minutes to 22 hours hh 2 hours ago ... 22 hours ago
22 to 36 hours d a day ago
36 hours to 25 days dd 2 days ago ... 25 days ago
25 to 45 days M a month ago
45 to 345 days MM 2 months ago ... 11 months ago
345 to 545 days (1.5 years) y a year ago
546 days+ yy 2 years ago ... 20 years ago

Calendar Time (based on Moment.js)

Range Output
Last week Last Monday at 2:30 AM
The day before Yesterday at 2:30 AM
The same day Today at 2:30 AM
The next day Tomorrow at 2:30 AM
The next week Sunday at 2:30 AM
Everything else 7/10/2011

bitwalker avatar Mar 07 '16 17:03 bitwalker

I'm using the relative formatter to show how long ago articles were submitted to a database. If they submit the article themselves, on the next page the relative date formatter displays "In 0 seconds", since there was a time difference of 0, which doesn't make much sense since in the context.

It should probably display something like "Right now". Moment.js puts in "a few seconds ago" despite the fact its 0. Either case would better than it is now for me.

Thanks!

mikelat avatar Apr 12 '16 23:04 mikelat

Thanks for the feedback @mikelat, sorry for the delay. I'll get that addressed in the next release :)

bitwalker avatar May 20 '16 23:05 bitwalker

Just wanted to say thanks for this. Any idea when the relative parser will be available? I looked at the branch and would love to contribute. Wasn't sure of the status though.

binarylogic avatar Jun 28 '16 21:06 binarylogic

@binarylogic once the release for Elixir 1.3 drops on Wednesday I'd be glad to provide guidance on the implementation, currently there is not a relative parser in progress, but building one is fairly straightforward :)

bitwalker avatar Jun 29 '16 00:06 bitwalker

Absolutely, I'd love to knock that out. I have a project that needs it. Let me know how / when you want to talk and I'll get started.

binarylogic avatar Jun 29 '16 03:06 binarylogic

Also, elixir 1.3 was just recently released.

binarylogic avatar Jun 29 '16 03:06 binarylogic

@binarylogic yeah I mean the Timex release for 1.3 ;)

bitwalker avatar Jun 29 '16 03:06 bitwalker

@binarylogic 1.3 introduced calendar types, so the types Timex introduced a long time ago are no longer necessary. Because of the new calendar API, I'm refactoring Timex to use those types instead, hence what I mean by "Timex release for 1.3".

bitwalker avatar Jun 29 '16 04:06 bitwalker

Awesome, sounds great. I'll keep an eye out and jump in when that's released.

binarylogic avatar Jun 29 '16 04:06 binarylogic

@bitwalker, is this still an active issue?

mbramson avatar Apr 04 '17 02:04 mbramson

It is, I just haven't had the time or need to work on this yet. It is definitely something I'd be glad to merge if someone wants to take on the work to put together a PR!

bitwalker avatar Apr 05 '17 19:04 bitwalker

@bitwalker this looks like something I would like to implement. Do you have any insights or suggestions before I jump into working on it?

CoderDennis avatar May 23 '23 13:05 CoderDennis