mirror of
https://github.com/harttle/liquidjs.git
synced 2026-10-03 00:55:13 -07:00
fix(date): compute %C and %y from the numeric year (#961)
Both were sliced from the year string, so years with other than four digits gave the wrong century and two-digit year, and %y was a string that the - and _ flags could not unpad. Compute them arithmetically and pad them to two digits, matching Ruby's strftime.
This commit is contained in:
@@ -18,6 +18,14 @@ describe('util/strftime', function () {
|
||||
it('should format %y as 2-digit year', function () {
|
||||
expect(t(now, '%y')).toBe('16')
|
||||
})
|
||||
it('should format %C and %y from the numeric year', function () {
|
||||
const year999 = new TestDate('0999-06-15 00:00:00')
|
||||
expect(t(year999, '%C')).toBe('09')
|
||||
expect(t(year999, '%y')).toBe('99')
|
||||
const year2005 = new TestDate('2005-06-15 00:00:00')
|
||||
expect(t(year2005, '%y')).toBe('05')
|
||||
expect(t(year2005, '%-y')).toBe('5')
|
||||
})
|
||||
describe('%j', function () {
|
||||
it('should format %j as day of year', function () {
|
||||
expect(t(then, '%j')).toBe('066')
|
||||
|
||||
Reference in New Issue
Block a user