mirror of
https://github.com/harttle/liquidjs.git
synced 2026-09-18 05:50:43 -07:00
fix(date): %s returns Unix epoch unaffected by display timezone (#932)
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 #931
This commit is contained in:
@@ -105,7 +105,7 @@ const formatCodes: Record<string, FormatCodeHandler> = {
|
||||
p: (d: LiquidDate) => (d.getHours() < 12 ? 'AM' : 'PM'),
|
||||
P: (d: LiquidDate) => (d.getHours() < 12 ? 'am' : 'pm'),
|
||||
q: (d: LiquidDate) => ordinal(d),
|
||||
s: (d: LiquidDate) => Math.round(d.getTime() / 1000),
|
||||
s: (d: LiquidDate) => Math.floor(d.dateValue() / 1000),
|
||||
S: (d: LiquidDate) => d.getSeconds(),
|
||||
u: (d: LiquidDate) => d.getDay() || 7,
|
||||
U: (d: LiquidDate) => getWeekOfYear(d, 0),
|
||||
|
||||
Reference in New Issue
Block a user