6

For hg, I can set formatting with --template key to output only date, like this:

> hg log -l1 --template "{date(date, '%Y-%m-%d %H:%M:%S')}\n"  
2016-10-07 10:22:41

I can use %z control to output timezone offset:

> hg log -l1 --template "{date(date, '%Y-%m-%d %H:%M:%S %z')}\n"
2016-10-07 10:22:41 +0300

Also, in OpenSuse date realization there is %:::z control for more readable format:

> date +'%Y-%m-%d %H:%M:%S %:::z'
2016-10-07 11:03:34 +03

It's not POSIX control, but is there a way to achieve something like this in hg log formatting? Simple way is not working:

> hg log -l1 --template "{date(date, '%Y-%m-%d %H:%M:%S %:::z')}\n"  
2016-10-07 10:22:41 %:::z

From man date:

%:::z numeric time zone with : to necessary precision (e.g., -04, +05:30)

1 Answer 1

5
+50

The isodate filter seems like the closest to what you want.

$ hg log -r1 --template 'date: {date|isodate}\n'
date: 2009-05-05 06:55 +0000

isodate: date keyword. Render the date as a text string in ISO 8601 format. Yields a string like “2006-09-04 15:13:13 -0700”.

To condense the timezone doesn't appear to be feasible. It's even mentioned in this SO Q&A titled: Stripping hg date.

Therefore I think you're best option will be to enlist the help using sed or awk to cleanup the output to suit your needs.

References

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .