This repository has been archived by the owner on Apr 17, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 73
Switch default values to UTC, and add sub-second values #80
Open
tpitale
wants to merge
3
commits into
datamapper:master
Choose a base branch
from
tpitale:support-utc-tz
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -193,11 +193,11 @@ VALUE data_objects_parse_date(const char *date) { | |
} | ||
|
||
VALUE data_objects_parse_time(const char *date) { | ||
static char const* const _fmt_datetime = "%4d-%2d-%2d%*c%2d:%2d:%2d%7lf"; | ||
int year = 0, month = 0, day = 0, hour = 0, min = 0, sec = 0, usec = 0; | ||
static char const* const _fmt_datetime = "%4d-%2d-%2d%*c%2d:%2d:%2d%7lf%3d:%2d"; | ||
int year = 0, month = 0, day = 0, hour = 0, min = 0, sec = 0, usec = 0, hour_offset, minute_offset; | ||
double subsec = 0; | ||
|
||
switch (sscanf(date, _fmt_datetime, &year, &month, &day, &hour, &min, &sec, &subsec)) { | ||
switch (sscanf(date, _fmt_datetime, &year, &month, &day, &hour, &min, &sec, &subsec, &hour_offset, &minute_offset)) { | ||
case 0: | ||
case EOF: | ||
return Qnil; | ||
|
@@ -210,18 +210,20 @@ VALUE data_objects_parse_time(const char *date) { | |
return Qnil; | ||
} | ||
|
||
// TODO: support the timezone being returned from | ||
return rb_funcall(rb_cTime, rb_intern("local"), 7, INT2NUM(year), INT2NUM(month), INT2NUM(day), INT2NUM(hour), INT2NUM(min), INT2NUM(sec), INT2NUM(usec)); | ||
} | ||
|
||
VALUE data_objects_parse_date_time(const char *date) { | ||
static char const* const _fmt_datetime_tz_normal = "%4d-%2d-%2d%*c%2d:%2d:%2d%3d:%2d"; | ||
static char const* const _fmt_datetime_tz_subsec = "%4d-%2d-%2d%*c%2d:%2d:%2d.%*d%3d:%2d"; | ||
static char const* const _fmt_datetime_tz_normal = "%4d-%2d-%2d%*c%2d:%2d:%2d%7lf%3d:%2d"; | ||
// static char const* const _fmt_datetime_tz_subsec = "%4d-%2d-%2d%*c%2d:%2d:%2d.%*d%3d:%2d"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure that there was a test for the '.' … or what it was meant to handle. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think it was actually used. Maybe an attempt to handle this case that never was finished? |
||
int tokens_read; | ||
const char *fmt_datetime; | ||
|
||
VALUE offset; | ||
|
||
int year, month, day, hour, min, sec, hour_offset, minute_offset; | ||
int year, month, day, hour, min, sec, usec, hour_offset, minute_offset; | ||
double subsec; | ||
|
||
struct tm timeinfo; | ||
time_t target_time; | ||
|
@@ -238,8 +240,10 @@ VALUE data_objects_parse_date_time(const char *date) { | |
* - DateTime [6 tokens, missing 2] | ||
* - DateTime with hour, possibly minute TZ offset [7-8 tokens] | ||
*/ | ||
fmt_datetime = strchr(date, '.') ? _fmt_datetime_tz_subsec : _fmt_datetime_tz_normal; | ||
tokens_read = sscanf(date, fmt_datetime, &year, &month, &day, &hour, &min, &sec, &hour_offset, &minute_offset); | ||
// fmt_datetime = strchr(date, '.') ? _fmt_datetime_tz_subsec : _fmt_datetime_tz_normal; | ||
tokens_read = sscanf(date, _fmt_datetime_tz_normal, &year, &month, &day, &hour, &min, &sec, &subsec, &hour_offset, &minute_offset); | ||
|
||
usec = (int) (subsec * 1000000); | ||
|
||
if(!year && !month && !day && !hour && !min && !sec) { | ||
return Qnil; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, this
local
call doesn't support setting the timezone AFAIK.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, we'd need to handle the cases different here then. Use
local
when there's no UTC offset present, but build an object with the specific UTC offset otherwise.