Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more date patterns and changed to a more lenient day and month parsing #312

Merged
merged 2 commits into from
Nov 18, 2024

Conversation

bkiers
Copy link
Owner

@bkiers bkiers commented Nov 18, 2024

Add more date patterns and changed to a more lenient day and month parsing: MM and dd changed to M and d. Now not only things like 2024-02-09 are parsed correctly, but also 2024-2-9

Fixes #309

Tested with Ruby:

# frozen_string_literal: true
require 'liquid'

tests = [
  "now",
  "today",
  "1 March",
  "MAR",
  "MARCH",
  "2024 MAR",
  "2 mar",
  "2 MAR",
  "march 2nd",
  "MARCH 2",
  "MARCH 2nd",
  "MARCH 3RD",
  "MARCH 4th",
  "MARCH 5th",
  "MARCH 10th",
  "2010-10-31",
  "Aug 2000",
  "Aug 31",
  "Wed Nov 28 14:33:20 2001",
  "Wed, 05 Oct 2011 22:26:12 -0400",
  "Wed, 05 Oct 2011 02:26:12 GMT",
  "Nov 29 14:33:20 2001",
  "05 Oct 2011 22:26:12 -0400",
  "06 Oct 2011 02:26:12 GMT",
  "2011-10-05T22:26:12-04:00",
  "0:00",
  "1:00",
  "01:00",
  "12:00",
  "16:30",
  "3/2024",
  "01/03",
  "03/31",
  "2001/03",
  "01/2003",
  "70-10-31"
]

tests.each do |test|
  template_string = "{% assign v1 = '#{test}' | date: '%s' %}{% assign v2 = '#{test}' | date: '%b %d, %y' %}{{ v1 }}, {{ v2 }}"
  template = Liquid::Template.parse(template_string)
  puts "#{test} -> #{template.render({})}"
end

which prints:

now -> 1731957693, Nov 18, 24
today -> 1731957693, Nov 18, 24
1 March -> 1709247600, Mar 01, 24
MAR -> 1709247600, Mar 01, 24
MARCH -> 1709247600, Mar 01, 24
2024 MAR -> 1709247600, Mar 01, 24
2 mar -> 1709334000, Mar 02, 24
2 MAR -> 1709334000, Mar 02, 24
march 2nd -> 1709334000, Mar 02, 24
MARCH 2 -> 1709334000, Mar 02, 24
MARCH 2nd -> 1709334000, Mar 02, 24
MARCH 3RD -> 1709420400, Mar 03, 24
MARCH 4th -> 1709506800, Mar 04, 24
MARCH 5th -> 1709593200, Mar 05, 24
MARCH 10th -> 1710025200, Mar 10, 24
2010-10-31 -> 1288476000, Oct 31, 10
Aug 2000 -> 965080800, Aug 01, 00
Aug 31 -> 1725055200, Aug 31, 24
Wed Nov 28 14:33:20 2001 -> 1006954400, Nov 28, 01
Wed, 05 Oct 2011 22:26:12 -0400 -> 1317867972, Oct 05, 11
Wed, 05 Oct 2011 02:26:12 GMT -> 1317781572, Oct 05, 11
Nov 29 14:33:20 2001 -> 1007040800, Nov 29, 01
05 Oct 2011 22:26:12 -0400 -> 1317867972, Oct 05, 11
06 Oct 2011 02:26:12 GMT -> 1317867972, Oct 06, 11
2011-10-05T22:26:12-04:00 -> 1317867972, Oct 05, 11
0:00 -> 1731884400, Nov 18, 24
1:00 -> 1731888000, Nov 18, 24
01:00 -> 1731888000, Nov 18, 24
12:00 -> 1731927600, Nov 18, 24
16:30 -> 1731943800, Nov 18, 24
3/2024 -> 1709247600, Mar 01, 24
01/03 -> 1704236400, Jan 03, 24
03/31 -> 1711839600, Mar 31, 24
2001/03 -> 983401200, Mar 01, 01
01/2003 -> 1041375600, Jan 01, 03
70-10-31 -> 26175600, Oct 31, 70

@bkiers bkiers requested a review from msangel November 18, 2024 19:17
@bkiers bkiers merged commit 4f2a07a into master Nov 18, 2024
4 checks passed
@bkiers bkiers deleted the 309-date-bug branch November 18, 2024 19:24
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.

Parsing today in unix format works fine but not with other dates
2 participants