Commit Graph

4 Commits

Author SHA1 Message Date
Jun Wu
186bdeb1bd hgtime: parse a range
Summary:
`hg` also supports matching a date range via `util.matchdate`. For example,
`Apr 2000` would mean `Apr 1, 2000 0:0:0 to Apr 30, 2000 23:59:59`.

Implement that behavior. Also support other formats covered by `hg help dates`
including `> DATE`, `< DATE`, `DATE to DATE`, and `-DAYS`.

Reviewed By: sfilipco

Differential Revision: D17504706

fbshipit-source-id: db1c280b62a72f4e8128909ca6fd814d85d22491
2019-10-08 11:11:02 -07:00
Jun Wu
785f0040c6 hgtime: parse "ago" time like "5 minutes ago"
Summary:
This is a feature that does not exist in hg. It has potential to unify the
`date` and `ago` revsets.

By using the `humantime` crate we can get this feature fairly easily.

Reviewed By: sfilipco

Differential Revision: D17504705

fbshipit-source-id: b888517114b91c847ae319552d07fe5a5a41cad3
2019-10-08 11:11:02 -07:00
Jun Wu
96c30fbd8a hgtime: parse incomplete dates
Summary:
Dates like `13:00` or `Apr 2010` cannot be parsed directly. Support them by
filling the missing fields.

This is mostly porting from `mercurial.util.parsedate` and
`mercurial.util.strdate`, with a small bug fixed: default value for month/day
are set to "1" instead of "0".

Reviewed By: sfilipco

Differential Revision: D17504703

fbshipit-source-id: dac9f5e4946c8d838f50ef1d4677741f6e4bc771
2019-10-08 11:11:02 -07:00
Jun Wu
4dff8e37f6 hgtime: new crate to work with time, esp for parsing
Summary:
I'd like a native `blackbox`-like command that accepts something like:

  --date 'since 3 hours ago'
  --date 'since yesterday'
  --date today
  --date 'Apr 2019' (implies a range of a month)
  --date 'Apr 2019 to Jul 2019'
  --date '13:00 to 15:00' (implies within today)

With a goal that this can be a superset and replace hg's date utilities,
and it can be used in `log --date`, revsets, etc.

Sadly, none of the top public Rust crates can sasity the existing features
("13:00" implying "today", "Apr 2019" implies a range of a month are two
less-known features that the Rust date utilties do not handle).

So I started porting the Python code (`mercurial.util.parsedate`) to Rust.

The core `parse` function is just 40 lines now.

Reviewed By: sfilipco

Differential Revision: D17504704

fbshipit-source-id: bde356a8cedf3298b060220de499e3954ed9d88b
2019-10-08 11:11:02 -07:00