jsonata-js / jsonata

JSONata query and transformation language - http://jsonata.org
MIT License
2.03k stars 216 forks source link

function to convert timestamp to locale time string #347

Open janvda opened 5 years ago

janvda commented 5 years ago

The function $fromMillis() can be used to convert a time to a string but it doesn't take the locale settings into account. (I know that it is possible to specify a timezone as parameter but due to daylight saving time you will need to adapt this timezone twice a year).

It would be interesting to have functions that converts a time/date to a locale time/date string like the javascript Date methods:

  1. toLocaleDateString()
  2. toLocaleTimeString()
  3. toLocaleString()
loganvolkers commented 4 years ago

You might be interested in jsonata-moment. You could also add your own. If those functions are popular, maybe they would be merged into the core language spec and included across the different implementations of JSONata

ScottG489 commented 1 year ago

Thought I'd mention I just came across this problem!

Adrian-Grimm commented 1 month ago

@andrew-coleman & @mattbaileyuk: what would you think of this approach to solve this issue?

The idea is to take the current timezone param and rename it to "offset", by keeping the offset value/logic like it was - and add a new timezone param which could dynamicly ajust the time to the valid tzdata(IANA) based timezone (summer/winter time and all further strange cases included..). All of this by don't have any breaking code changes - only for documentation ...

Targets: $now() and $fromMillis()

If it's OK, I could clean it up and provide a pull for it.