-
Notifications
You must be signed in to change notification settings - Fork 8
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
Change feeds to use local datetime #69
Conversation
I'm not super experienced with date handling code, so I don't have a super strong opinion on it, but can you explain the decision to store time as local times and do math with UTC? Also, will this tolerate the switch-over? I suspect the |
When we check if comic is scheduled, we convert parsed datetime to localtime and check elapsed time against that.
Now that I think of it, it is much easier to parse datetime as Utc, as it was before, and when we check if comic is scheduled, we just convert this Utc datetime to our local time and check elapsed time against that. It is much better solution, I don't know why I didn't think of that earlier. Changed the commit to reflect latest changes. |
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.
Wow, this became much simpler.
I think there are a few more changes in is_scheduled
that need to be made in order to avoid some edge cases that weren't properly handled previously though, and it'd be good to fix those here.
src/feed.rs
Outdated
@@ -157,7 +157,8 @@ impl Feed { | |||
} | |||
|
|||
pub fn is_scheduled(&self) -> bool { | |||
let elapsed_time = Utc::now().signed_duration_since(self.last_read); | |||
let last_read = self.last_read.with_timezone(&Local); | |||
let elapsed_time = Local::now().signed_duration_since(last_read); |
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.
The On
case probably needs to loop from the last_read
's day all the way to the now
day, rather than using elapsed_time.num_days()
, to account for incomplete days.
Exploring the semantics of the
If you could add test cases for these two edge cases, that would also be very much appreciated. |
Since it makes it easier to test, I'd also approve of changing |
Ok, I changed the is_scheduled to accept datetime, I also changed how is determined if the feed has already been read at least one. Before you would store MIN_DATE if you did not read it at least once, now it is Option with Some(DateTime) or None if the feed has not been read. |
Do you want to handle those other edge condition issues I brought up, or do you want me to make that a separate issue? This is a good improvement already, so it's up to you. |
Yeah, maybe it'll be better to open separate issue. We can then discuss how to handle these two edge cases properly. |
Okay, in that case, you need to re-run rustfmt on this so Travis will accept it. |
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.
LGTM
Merged, thanks for your fix! |
Internally the Feed struct uses Utc datetimes converted from local datetimes.
Datetime stored in feed files are always stored as local.
The basic process is:
I must say the test_parse_events test, gave me pretty hard time to fix, I could not find simple way to get the offset from Utc datetime to Local datetime in chrono crate, but it works now.
Fixes #58