d3 / d3-time-format

Parse and format times, inspired by strptime and strftime.
https://d3js.org/d3-time-format
ISC License
328 stars 99 forks source link

%Z behavior does not match strftime #111

Closed chasetec closed 2 years ago

chasetec commented 2 years ago

The docs say that d3-time-format provides a JavaScript implementation of strftime

However if you read the linked Single UNIX Specification behavior for %Z it should provide "timezone name or abbreviation".

const commonTime = d3.timeFormat('%d/%b/%Y:%H:%M:%S %Z');
console.log(commonTime(new Date()));

Is producing 19/Feb/2022:11:39:16 -0600 which shows the timezone offset from UTC in the ISO 8601:2000 standard format ( +hhmm or -hhmm ), not a name or abbreviation.

The current behavior of %Z matches what was later added to updated strftime as %z.

To match strftime, swap %Z to %z and add %Z to display timezone as a name or abbreviation.

chasetec commented 2 years ago

Name or abbreviation would be something like Central Daylight Time or CDT.

mbostock commented 2 years ago

This library isn’t intended to be exactly compatible with strftime in UNIX, or similar methods in Python, e.g. The documentation for %Z in the README looks correct. Also JavaScript won’t have support for named timezones until the Temporal API is widely available (at least not without major workarounds) so this probably would be hard to support anyway.