Closed jairinhohw closed 4 years ago
hi @jairinhohw many thanks for the fixes.
Instead of having to pass the timezone as a 3rd argument what about better changing or find what could be used as the 2nd argument (probably only the UNIX timestamp), If a different time zone is required the timestamp can be configured in advance and just pass it as an argument.
The idea with this is to make the parse method more "idempotent" if we could call it that way so that by using the cron expression and the timestamp
should always return the same thing regarding the timezone (that if properly adjusted in the input should match)
What do you think?
Or probably better to have use something like:
pub fn parse<TZ: TimeZone>(cron: &str, dt: DateTime<TZ>) -> Result<DateTime<TZ>, ParseError>
@jairinhohw please check the latest branch develop, is using
pub fn parse<TZ: TimeZone>(cron: &str, dt: DateTime<TZ>) -> Result<DateTime<TZ>, ParseError>
So that you just need to pass the Datetime in your desired zone, please check it and let me know your thoughts.
Think I like is that still working as before with UTC:
parse("*/5 * * * *", Utc::now());
Or you could pass your desired timezone:
use chrono_tz::US::Pacific;
parse("*/5 * * * *", Utc::now().with_timezone(&Pacific));
It seems much better, i didn't know you could get the timezone with this timezone
method.
That was the only reason i passed the tz
argument.
About the TODO in line 112, by looking at the implementation, it's impossible for the unwrap to fail.
hi @jairinhohw Regarding the line https://github.com/nbari/cron-parser/blob/develop/src/lib.rs#L175
// Valid datetime for the timezone
if let Some(dt) = tz.from_local_datetime(&next.naive_local()).latest() {
Why the usage of latest()
?
Is possible in some timezones (with DST) that one date occur more than one time, when the DST ends and the time goes back one hour.
I feared that getting the earliest date it could cause an infinite loop in some instances by getting various dates using the result of the parse
as de initial date of the new parse
.
I see, the latest
will use the second T
from Ambiguous(T, T)
right?
Yes
Got it many thanks 👍
I modified your crate for my use case, so it can use other timezones I don't know if it's a good implementation, but it seems to work