fmeringdal / rust-rrule

Rust crate for working with recurrence rules for calendar dates as defined in the iCalendar RFC and more.
https://docs.rs/rrule
Apache License 2.0
71 stars 18 forks source link

Force use `UTC` as local timezone with feature flag #36

Open ralpha opened 2 years ago

ralpha commented 2 years ago

Some parts of the spec specify that local time should be used as default in some cases. The system timezone of the machine will be used in those cases (or should be used). With a feature flag this should default to UTC regardless where the system is currently located/configured.

This feature is useful when the crate is used on servers.

Alternatively an environment variable can be used to specify the desired fixed timezone.

omid commented 2 years ago

I suggest having a method, inside RRuleSet, instead of having a feature flag. Again, Cargo requires that features are additive and it may affect other libraries unexpectedly.

fmeringdal commented 2 years ago

Another option which I am thinking about is making RRuleSet generic over the timezone used. Then the server code will look something like this:

use chrono::Utc;

let rrule_set: RRuleSet<Utc> = "DTSTART:...".parse().unwrap();

// Below will yield occurrences in Utc timezone
rrule_set.all(100); 

This approach will also solve #49 where generated occurrences should be in Local timezone and not chrono_tz::Tz.

use chrono::Local;

let rrule_set: RRuleSet<Local> = "DTSTART:...".parse().unwrap();

// Below will yield occurrences in Local timezone
rrule_set.all(100);