-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Upgrade time
to 0.2.5
#1254
Upgrade time
to 0.2.5
#1254
Conversation
Removing |
I feel the same way, which is why I submitted this PR to get some feedback on that. It's strange - in C's format pattern list (which time 0.1 uses verbatim, which changed in 0.2), %Z is documented as being the timezone's name, but the following time 0.1 code returns true, making me think that preserving %Z doesn't matter: let format = "%a, %d %b %Y %H:%M:%S %Z";
let dt_a = time::strptime("Sun, 07 Nov 1994 08:48:37 PST", format).unwrap();
let dt_b = time::strptime("Sun, 07 Nov 1994 08:48:37 UTC", format).unwrap();
println!("Match: {}", dt_a.eq(&dt_b)); |
The Tm {
tm_sec: 37,
tm_min: 48,
tm_hour: 8,
tm_mday: 7,
tm_mon: 10,
tm_year: 94,
tm_wday: 0,
tm_yday: 0,
tm_isdst: 0,
tm_utcoff: 0,
tm_nsec: 0
} Being that those two times are different timezones entirely, you'd expect |
Here's some further reading in regards to %Z's removal in time 0.2, from an issue from 2014 that was updated recently. In general, it seems like %Z would never work without proper IANA TZ support, in either Rust or C. One option is to use UTC offsets instead - %z - but I don't know if that's the right thing to do here. |
we should drop chrono as well |
I removed the only instance of Aside from that, even though |
One issue I just discovered with that switch to I've made further adjustments so that we never use |
…DateTime::parse`
could you add entries to changes.md to all updated crates |
Done! I also fixed up a few test related errors that popped up from these recent modifications as well. |
After updating my branch with master and having the tests rerun, two tests now fail. The first one is let max_seconds = Duration::max_value().whole_seconds();
max_seconds + 1; The reason this is now an issue, but wasn't one before is because let max_seconds = Duration::max_value().num_seconds();
If we'd like to keep this test, then I think changing it to something similar to how #[test]
fn do_not_panic_on_large_max_ages() {
let max_duration = Duration::max_value();
let expected = Cookie::build("foo", "bar").max_age(max_duration.whole_seconds()).finish();
assert_eq_parse!(format!(" foo=bar; Max-Age={:?}", max_duration.checked_add(Duration::seconds(1)).unwrap_or(max_duration).whole_seconds()), expected);
} However, this does mean that doing a simple #[test]
fn do_not_panic_on_large_max_ages() {
let max_duration = Duration::max_value();
let expected = Cookie::build("foo", "bar").max_age_time(max_duration).finish();
let overflow_duration = max_duration.checked_add(Duration::seconds(1)).unwrap_or(max_duration);
assert_eq_parse!(format!(" foo=bar; Max-Age={:?}", overflow_duration.whole_seconds()), expected);
} |
The second one is PrimitiveDateTime {
date: Date { year: 1994, ordinal: 311 },
time: Time { hour: 8, minute: 48, second: 37, nanosecond: 0 }
} it outputs this: PrimitiveDateTime {
date: Date { year: 94, ordinal: 311 },
time: Time { hour: 8, minute: 48, second: 37, nanosecond: 0 }
} which obviously fails due to that year being 94. I'm not sure if this is a bug with |
For reference in regards to that second test, when using Tm {
tm_sec: 37,
tm_min: 48,
tm_hour: 8,
tm_mday: 7,
tm_mon: 10,
tm_year: 94,
tm_wday: 0,
tm_yday: 0,
tm_isdst: 0,
tm_utcoff: 0,
tm_nsec: 0
} which also has a year of 94. In time::strptime( "Sun, 07 Nov 1994 08:48:37 GMT", "%a, %d %b %Y %H:%M:%S") results in the exact same Two solutions I've thought of are to either remove support for non-RFC 822 time strings (and only ever try to parse those, rejecting anything else, seeing as they have seemingly invalid |
…h year, and organize time parsing related functions
After some thought and reading through the HTTP RFCs for HTTP Date, I was able to come up with a solution for the
|
i agree with your solution, main problem at the moment is backward compatibility. |
With that fix in place, now the I've yet to be figure out a solution to this, as every combination of format patterns I've tried hasn't parsed the test's time string successfully. To show what I mean:
time::strptime("Sun Nov 7 08:48:37 1994", "%c") produced this Tm {
tm_sec: 37,
tm_min: 48,
tm_hour: 8,
tm_mday: 7,
tm_mon: 10,
tm_year: 94,
tm_wday: 0,
tm_yday: 0,
tm_isdst: 0,
tm_utcoff: 0,
tm_nsec: 0
}
PrimitiveDateTime::parse("Sun Nov 7 08:48:37 1994", "%c") produces an I've been attempting to recreate Using pattern PrimitiveDateTime {
date: Date { year: 1994, ordinal: 320 },
time: Time { hour: 8, minute: 48, second: 37, nanosecond: 0 }
} This seems like a bug within |
@fafhrd91 Time v0.1's support for And just looking through this issue, |
PSA: I may be reverting the change to a non-additive "alloc" feature in favor of the additive "std" feature. I thought the change was necessary due to serde — turns out it's not. Sorry for the back-and-forth! |
v0.2.3 has been yanked, as it was backwards imcompatible. This version reverts the breaking change, while still supporting rustc back to 1.34.0.
PR is up from mine to the fork. All that's changed is the I assure you you can merge this now 😛 v0.2.3 has been yanked as well, so anything backwards-incompatible has been extremely limited. |
Upgrade to time v0.2.4
Merged @jhpratt's PR into my fork - this should be ready to merge now! |
@jhpratt: Just now noticing some issues with running cargo check after your change to 0.2.4 - it doesn't seem to want to find |
For With regard to parsing, you can either use the specific type (like |
The missing As for the type confusion though, I brought it up because using Using this Starting off with how the code is structured in the test: let time_str = "Wed, 21 Oct 2015 07:28:00 GMT";
let time = time::parse(time_str, "%a, %d %b %Y %H:%M:%S").unwrap().using_offset(offset!(UTC));
print_time(time); Output:
Separating the offset into its own variable: let time_str = "Wed, 21 Oct 2015 07:28:00 GMT";
let time = time::parse(time_str, "%a, %d %b %Y %H:%M:%S").unwrap();
let offset = time.using_offset(offset!(UTC));
print_time(offset); Output:
Lastly, removing the offset completely: let time_str = "Wed, 21 Oct 2015 07:28:00 GMT";
let time = time::parse(time_str, "%a, %d %b %Y %H:%M:%S").unwrap();
print_time(time); Output:
Changing I think the best thing to do here is to use |
Okay, I just got the overview.
And I think this can be considered as a breaking change in some crate, so I'm going to mark so. |
Thanks @kevinpoitra and @jhpratt! |
You're welcome! As soon as the |
Some notable changes:
The %Z timezone format pattern doesn't exist in
time
0.2. Seeing that in C'sstrptime
function, %Z is seemingly ignored (Sun, 07 Nov 1994 08:48:37 PST
andSun, 07 Nov 1994 08:48:37 UTC
return the same time), I opted to just remove it from any relevant parsing format strings, and just replaced it with 'GMT' for anyformat()
strings.time
0.1's %T format pattern would resolve to%H:%M:%S
, whereas time 0.2's %T uses%-H:%M:%S
instead (removing any padding). I replaced any instances of %T with %H:%M:%S to keep it the same.