-
Notifications
You must be signed in to change notification settings - Fork 357
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
Full Timezone Support #335
base: master
Are you sure you want to change the base?
Conversation
Change offset without changing time
like PDT, PST, etc.
not TimeWithZone, while when parsing a timezone it is a TimeWithZone
@seejohnrun any chance of getting this merged in? |
@dcosson nice and thank you! - what about the case where |
Would love to see this get merged in! Any chance non- I'm having a problem right now with a Rails app I have running on Heroku. The system time zone of Heroku machines is set to UTC I believe, which means all of my IceCube::Schedule objects save with the incorrect timezone currently. |
To be honest I've never used ruby without ActiveSupport and my snarky first thought is why would anyone even bother :) I can try to get this working if that's the blocker though. It looks like the only code path that assumes ActiveSupport timezone is available is when you parse an ical string that has a TZID. Can I just raise an explicit exception in this case? Or is there another way to use TZInfo without ActiveSupport? |
@dcosson You may be able to use this gem: https://github.com/tzinfo/tzinfo You could make that a dependency of IceCube and use it for parsing dates using whatever timezone is passed in TZID. It doesn't look like it depends on ActiveSupport. Maybe use ActiveSupport by default and use the gem above as a fallback? EDIT: Just realized that's the exact gem ActiveSupport uses right now. |
@dcosson @seejohnrun Put some more thinking / console testing into this and I may have a solution. We can modify the time zone parser to use def self._parse_in_tzid(value, tzid)
time_zone = tzid ? tzid.split('=')[1] : Time.zone
Time.use_zone time_zone do
Time.zone.parse(value)
end
end This will switch ActiveSupport::TimeZone.new(time_zone).parse(value) EDIT: Nevermind, I had ActiveSupport loaded somehow in my Ruby console. |
@Tybot204 but isn't |
@seejohnrun Ya I edited my post above to say that. I didn't realize it was an extension on |
Ah - sorry didn't see that @Tybot204 |
Also - I guess I could be down to add ActiveSupport as a dependency, but On Wed, Jul 6, 2016 at 1:25 PM Tyler Hogan [email protected] wrote:
|
Yeah, so I think the options are to include ActiveSupport as a dependency or raise an exception when parsing an ical string if it has a TZID but ActiveSupport is not available. I guess I can see pros & cons to both - it's obviously an extra dependency, but by not requiring it as a gem dependency people might think they have this library fully installed and then unexpectedly get exceptions in production the first time they try to parse strings with tzid. |
How about when they want the parser having them require in that separately Another idea would be a separate gem but that feels like overkill
|
@seejohnrun not quite sure I understand the first suggestion. Unless I'm forgetting something, you don't interact with the parser directly, you call e.g. |
I'm strongly in favour of making dependencies on libraries like ActiveSupport optional, preferably ignoring them altogether. And let's not forget that people who serialize data don't automatically choose ActiveRecord – there are good reasons to choose different ways of storing data, or different libraries for interacting with a relational DB. @dcosson What I think @seejohnrun meant when he said "How about when they want the parser having them require in that separately" was that people who need the functionality that depends on ActiveSupport could require that gem themselves (e.g. add it to their bundle) in order to disable the exception you proposed, and enable the functionality. |
Agree with @gma I also think we could make it even nicer if we provide a wrapper around the require 'ice_cube/parsing' # which requires active_support
Parser.schedule_from_yaml(yaml) just an idea - but definitely don't want to add AS as a dependency |
@seejohnrun @dcosson thanks |
@dimerman I'll try to get this worked up as suggested above this week some time. I definitely want to get this in, just don't want to introduce an AS requirement for those who don't want to add it. |
This adds full timezone support to ice_cube (when using ActiveSupport). It builds off of (and supercedes) #295
The naming when discussing timezones gets confusing, there are named UTC offsets (such as PDT = UTC - 7 hours and PST = UTC - 8 hours) that are often referred to as timezones. There are also timezones that map to a geographical region and account for daylight savings time there, such as those specified in the IANA Timezone Database like "America/Los_Angeles". These are also referred to as timezones. The latter is much more useful, because you can represent things like 5 hours after midnight on the boundary of a daylight savings time border and get the right value.
Previously the
to_ical
method with timezones enabled uses "%Z" strftime which outputs timezone offsets like PDT, but it should instead output timezones from the IANA timezone database. This PR updates this.The code in #295 for
from_ical
is already expecting the timezone to be of the latter format, so that code works as expected.