Skip to content
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

Support for when only time zone UTC offsets are known #40

Open
mwaterfall opened this issue Feb 14, 2014 · 5 comments
Open

Support for when only time zone UTC offsets are known #40

mwaterfall opened this issue Feb 14, 2014 · 5 comments

Comments

@mwaterfall
Copy link

I'm having to handle time zones where I only know the UTC offset and no specific time zone identifier string. I'd still like to be able to plug in these into Delorean as my app is already built around Delorean because of it's awesomeness!

I'm generating tzinfo objects using pytz's (rather hidden) FixedOffset class, but as there is no standard for naming such offsets, there's no way for me to plug them in to Delorean.

So it would be awesome if I could either pass tzinfo objects straight into any timezone argument, or whether Delorean could parse certain strings (perhaps in the ISO 8601 UTC time offset format i.e. ±hh:mm, ±hhmm, ±hh) and then Delorean could create tzinfo objects from those using the FixedOffset class or similar.

Would be great to hear your thoughts.

@mwaterfall
Copy link
Author

I'm happy to dive in and see if I can get this working if we can decide on the best approach, so let me know if you'd be open to receiving some pull requests ;-)

@myusuf3
Copy link
Owner

myusuf3 commented Feb 15, 2014

@mwaterfall have you tried using the parse functionality inside delorean? I think it supports ISO 8601? If not, let me see what I can do it.

@myusuf3
Copy link
Owner

myusuf3 commented Feb 15, 2014

Looks like it converts it to UTC, I might have sometime this weekend.

@mwaterfall
Copy link
Author

Yes it supports and parses ISO 8601 perfectly, however as you say, Delorean returns the correct time in UTC. As dates with a UTC offset in hours/mins are common over the internet it would be great if it could be handled.

I've just seen the tzoffset type that dateutil offers, so that's useful.

It looks like RFC822 dates use the same format for offsets too, so parsing the offset in hours/mins from the string should be fairly straightforward.

Let me know if I can be of any help!

@mlew
Copy link
Collaborator

mlew commented Aug 8, 2015

@mwaterfall - I'm having a hard time parsing your problem. It sounds like you are able to use parse to create Delorean objects with a fixed offset (ex. '-0700'). Once Delorean parses your input it converts the time to UTC, so when you want to return a datetime object from the Delorean object you are unable to convert the datetime back to the original fixed offset.

If you knew the name of the timezone that for the datetime, you could convert it using shift, but shift does not understand fixed offset.

In other words, what you would like to do is something like the following:

>>> d = parse('2015-01-01 00:00:00 -0800')
>>> d.shift('-0800')
>>> d.datetime
datetime.datetime(2015, 1, 1, 0, 0, tzinfo=tzoffset(None, -28800))

The other option I can imagine is a new class property that returns a localized datetime object, like this:

>>> d = parse('2015-01-01 00:00:00 -0800')
>>> d.local_datetime
datetime.datetime(2015, 1, 1, 0, 0, tzinfo=tzoffset(None, -28800))

The first change seems pretty simple, but the second will require a bit more work because Delorean objects will have to remember their local timezone after they've been parsed. I have a feeling you're looking for the functionality in the later. Can you confirm?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants