Skip to content

fix(date): %s returns Unix epoch unaffected by display timezone#932

Merged
harttle merged 1 commit into
harttle:masterfrom
amit777:fix-epoch-timezone-shift
Jul 10, 2026
Merged

fix(date): %s returns Unix epoch unaffected by display timezone#932
harttle merged 1 commit into
harttle:masterfrom
amit777:fix-epoch-timezone-shift

Conversation

@amit777

@amit777 amit777 commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Fixes #931

%s read LiquidDate.getTime(), which returns the displayDate deliberately shifted by the display timezone offset (so wall-clock getters can delegate to Date). With a timezone filter argument or the timezoneOffset option set, %s produced an epoch shifted by (server offset − display offset) instead of the true Unix timestamp — the same template rendered different epochs depending on the host timezone.

{{ "2026-06-30T21:00:00Z" | date: "%s", "America/Toronto" }}
before: 1782838800 (on a UTC host)
after:  1782853200

Changes:

  • Expose the unshifted time as LiquidDate.dateValue() and use it for %s, making it timezone-invariant.
  • Math.roundMath.floor so fractional seconds truncate toward the epoch like Ruby strftime.
  • 4 new tests (timezone name argument, offset argument, timezoneOffset option, truncation); full suite passes under Etc/GMT, Asia/Shanghai, and America/New_York.
  • Docs: note in the date filter's TimeZone section that %s identifies an instant and is not affected by the display timezone.

The %s handler read LiquidDate.getTime(), which returns the
displayDate deliberately shifted by the display timezone offset for
wall-clock getters. With a timezone argument or timezoneOffset
option set, %s produced an epoch shifted by (server offset - display
offset) instead of the true Unix timestamp.

Expose the unshifted time as LiquidDate.dateValue() and use it for
%s. Also switch Math.round to Math.floor so fractional seconds
truncate toward the epoch like Ruby strftime.

Fixes harttle#931
@harttle
harttle merged commit 39c8743 into harttle:master Jul 10, 2026
14 checks passed
@amit777
amit777 deleted the fix-epoch-timezone-shift branch July 10, 2026 18:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

date filter: %s returns a timezone-shifted value when a display timezone is set

2 participants