diff options
author | Eric Wong <e@80x24.org> | 2021-04-16 18:43:06 -0500 |
---|---|---|
committer | Eric Wong <e@80x24.org> | 2021-04-16 22:24:44 -0400 |
commit | fd3b46aa0577d62553f61054270db6626ccc6759 (patch) | |
tree | 7789d2d2914be5e8026d82a5607b7746c460db29 /lib/PublicInbox/Search.pm | |
parent | 4ccc021183fe691c3229ff36e54ded8b305fcb71 (diff) | |
download | public-inbox-fd3b46aa0577d62553f61054270db6626ccc6759.tar.gz |
If a user specifies "d:" with a higher precision than it was traditionally able to handle, switch transparently to "dt:". This lowers the learning curve and improves DWIM-ness. v2: fix "d:YYYYMMDD..$NEEDS_APPROXIDATE" case
Diffstat (limited to 'lib/PublicInbox/Search.pm')
-rw-r--r-- | lib/PublicInbox/Search.pm | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/lib/PublicInbox/Search.pm b/lib/PublicInbox/Search.pm index ab04d430..fbcff2c3 100644 --- a/lib/PublicInbox/Search.pm +++ b/lib/PublicInbox/Search.pm @@ -275,7 +275,9 @@ sub date_parse_prepare { # expand "d:20101002" => "d:20101002..20101003" and like # n.b. git doesn't do YYYYMMDD w/o '-', it needs YYYY-MM-DD + # We upgrade "d:" to "dt:" to iff using approxidate if ($pfx eq 'd') { + my $fmt = "\0%Y%m%d"; if (!defined($r[1])) { if ($r[0] =~ /\A([0-9]{4})([0-9]{2})([0-9]{2})\z/) { push @$to_parse, "$1-$2-$3"; @@ -283,14 +285,27 @@ sub date_parse_prepare { # to parse anyways for "d+" below } else { push @$to_parse, $r[0]; + if ($r[0] !~ /\A[0-9]{4}-[0-9]{2}-[0-9]{2}\z/) { + $pfx = 'dt'; + $fmt = "\0%Y%m%d%H%M%S"; + } } - $r[0] = "\0%Y%m%d$#$to_parse\0"; - $r[1] = "\0%Y%m%d+\0"; + $r[0] = "$fmt+$#$to_parse\0"; + $r[1] = "$fmt+\0"; } else { for my $x (@r) { next if $x eq '' || $x =~ /\A[0-9]{8}\z/; push @$to_parse, $x; - $x = "\0%Y%m%d$#$to_parse\0"; + if ($x !~ /\A[0-9]{4}-[0-9]{2}-[0-9]{2}\z/) { + $pfx = 'dt'; + } + $x = "$fmt$#$to_parse\0"; + } + if ($pfx eq 'dt') { + for (@r) { + s/\0%Y%m%d/\0%Y%m%d%H%M%S/; + s/\A([0-9]{8})\z/${1}000000/; + } } } } elsif ($pfx eq 'dt') { |