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 read/write methods for date, time, and datetime types #8787

Merged
merged 2 commits into from
Mar 14, 2018

Conversation

daviditen
Copy link
Member

Add readWriteThis methods for the date, time, datetime types. Add a test to
ensure that the methods can be called and that they output and input matching
values when appropriate.

Add `readWriteThis` methods for the date, time, datetime types. Add a test to
ensure that the methods can be called and that they output and input matching
values when appropriate.
@buddha314
Copy link

Go David Go!!

@marcoscleison
Copy link

This issue is important. Thanks!

Copy link
Member

@mppf mppf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like to discuss the { } choice more before you merge, but I'm happy with the other elements here.

proc date.readWriteThis(f) {
var dash = new ioLiteral("-");
f <~> new ioLiteral("{") <~> chpl_year <~> dash <~> chpl_month <~> dash
<~> chpl_day <~> new ioLiteral("}");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a specific reason for the { } around the date? I'd think 2018-03-12 is clear enough as a date already. Are you following some Python precedent, e.g.?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was following the default behavior of Chapel classes, which doesn't make a whole lot of sense given that these are records. I'll remove the curly braces.

var colon = new ioLiteral(":");
f <~> new ioLiteral("{") <~> chpl_hour <~> colon <~> chpl_minute <~> colon
<~> chpl_second <~> new ioLiteral(".") <~> chpl_microsecond
<~> new ioLiteral("}");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same question here about {.

@@ -0,0 +1,3 @@
datetime: true
date: true
time: true
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have any tests that actually show the date-time formats in the .good file? Might be worth adding one so we can be sure it doesn't accidentally change.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll add one.

@mppf
Copy link
Member

mppf commented Mar 12, 2018

Should this be following ISO 8601?

@mppf
Copy link
Member

mppf commented Mar 12, 2018

Also I think the original issue, and your test, are about JSON format I/O - but a date field in JSON presumably needs to be inside double quotes - i.e. represented as a string in JSON since JSON doesn't support dates/times directly.

@buddha314
Copy link

@mppf you probably have a point. I'm not sure the proper way to set it.

@mppf
Copy link
Member

mppf commented Mar 12, 2018

The readWriteThis methods can check for json like so:

      var binary = f.binary();
      var arrayStyle = f.styleElement(QIO_STYLE_ELEMENT_ARRAY);
      var isjson = arrayStyle == QIO_ARRAY_FORMAT_JSON && !binary;

@daviditen
Copy link
Member Author

Should this be following ISO 8601?

This means zero-padding the year to 4 digits and everything else to 2 digits, plus putting a 'T' between the date and time, right? The padding sounds fine, but I'm not crazy about the 'T'.

@mppf
Copy link
Member

mppf commented Mar 13, 2018

Should this be following ISO 8601?

This means zero-padding the year to 4 digits and everything else to 2 digits, plus putting a 'T' between the date and time, right? The padding sounds fine, but I'm not crazy about the 'T'.

I think so... and generally agree. But at least ISO 8601 is a standard.

Zero-pad years to 4 digits and other fields to 2 digits. Make date and time be
separated by a 'T'.  Make dates/times/datetimes a string when reading or writing
for JSON.

Added a test that prints a date, time, and datetime value to lock in the format.
@mppf
Copy link
Member

mppf commented Mar 14, 2018

Looking good, thanks.

@daviditen
Copy link
Member Author

Thank you @mppf!

@daviditen daviditen merged commit 907daa5 into chapel-lang:master Mar 14, 2018
@daviditen daviditen deleted the datetime-read-write branch March 14, 2018 20:18
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.

4 participants