google / gitiles

A simple browser for Git repositories.
https://gerrit.googlesource.com/gitiles/
Other
582 stars 174 forks source link

Date-time format in +log JSON is not easily parsable #167

Open whesse opened 5 years ago

whesse commented 5 years ago

The date/time format in the JSON output of the +log endpoint is hard to parse without including internationalization libraries. It includes month names in English, and can't be parsed in Dart without writing a custom conversion function that includes conversion of months and parsing.

Issue #26 has some discussion about this, but the explanation doesn't say why the ISO format wasn't used. The only difference is that it doesn't show the day of the week, and it shows the month as a number. And most languages have support for parsing ISO format.

whesse commented 5 years ago

I suppose the comment in issue #26, that users can easily write their own parser for the user-readable format, is true. This issue can be closed. Example in Dart of converting this format to ISO format:

DateTime parseGitilesDateTime(String gitiles) { final parts = gitiles.split(' '); final year = parts[4]; const month = { 'Jan': '01', 'Feb': '02', 'Mar': '03', 'Apr': '04', 'May': '05', 'Jun': '06', 'Jul': '07', 'Aug': '08', 'Sep': '09', 'Oct': '10', 'Nov': '11', 'Dec': '12' }[parts[1]]; final day = parts[2].padLeft(2, '0'); return DateTime.parse('$year-$month-$day ${parts[3]} ${parts[5]}'); }

jrn commented 5 years ago

I think it would be reasonable to support a query parameter to request UNIX time.

ao2 commented 5 years ago

The date format in JSON output is the same used by git log by default, it can be parsed with generic time/data tools like strptime.

An example with jq to convert that date to the RFC 5322 format used in git format-patch:

cat out.json | jq '.author.time | strptime("%a %b %d %H:%M:%S %Y") | strftime("%a, %d %b %Y %H:%M:%S") + .[8]'