arrow-py / arrow-py/arrow

Return full Olsen timezone from an arrow object

Open
#343 8 comments 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
Python
Stars
9.1k
Forks
784
PR merge metrics
No merged PRs in 30d

Description

I've been using arrow for a while in my project, and I really like the clean semantics around timezones. However, I just ran into a small hole in timezone support, and I'm really hoping you can fix it, or at least, tell me how to work around it.

Here's my use case:
- I want to retrieve the timezone from an arrow object
- I want to save that timezone (as part of a JSON object)
- I want to retrieve that timezone and use it to reconstruct a new arrow object

Seems straightforward, right?

Not so fast!

arrow does not have `timezone` or `tz` attributes

```
In [8]: arrow.Arrow(year=2016, month=3, day=1, tzinfo=tz.gettz("Asia/Calcutta")).timezone---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
in ()
----> 1 arrow.Arrow(year=2016, month=3, day=1, tzinfo=tz.gettz("Asia/Calcutta")).timezone

/Users/shankari/OSS/anaconda/lib/python2.7/site-packages/arrow/arrow.pyc in __getattr__(self, name)
313 return value
314
--> 315 return object.__getattribute__(self, name)
316
317 @property

AttributeError: 'Arrow' object has no attribute 'timezone'

In [9]: arrow.Arrow(year=2016, month=3, day=1, tzinfo=tz.gettz("Asia/Calcutta")).tz
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
in ()
----> 1 arrow.Arrow(year=2016, month=3, day=1, tzinfo=tz.gettz("Asia/Calcutta")).tz

/Users/shankari/OSS/anaconda/lib/python2.7/site-packages/arrow/arrow.pyc in __getattr__(self, name)
313 return value
314
--> 315 return object.__getattribute__(self, name)
316
317 @property

AttributeError: 'Arrow' object has no attribute 'tz'
```

It does have a `tzinfo` defined, but that returns a `tzfile`

```
In [10]: arrow.Arrow(year=2016, month=3, day=1, tzinfo=tz.gettz("Asia/Calcutta")).tzinfo
Out[10]: tzfile('/usr/share/zoneinfo/Asia/Calcutta')
```

And there does not appear to be an easy way to extract the `Asia/Calcutta` from the `tzfile` - using obvious methods like `tzname` just return `'IST'`

```
In [11]: arrow.Arrow(year=2016, month=3, day=1, tzinfo=tz.gettz("Asia/Calcutta")).tzname()
Out[11]: 'IST'

In [12]: a = arrow.Arrow(year=2016, month=3, day=1, tzinfo=tz.gettz("Asia/Calcutta"))

In [13]: a.tzinfo.tzname(a.datetime)
Out[13]: 'IST'
```

And since `'IST'` is not a valid OLSON timezone, it cannot be used to look up the timezone while creating a new Arrow object.

```
In [14]: arrow.Arrow(year=2016, month=3, day=1, tzinfo=tz.gettz("Asia/Calcutta"))
Out[14]:

In [15]: arrow.Arrow(year=2016, month=3, day=1, tzinfo=tz.gettz("IST"))
Out[15]:
```

Any thoughts/suggestions?

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the Arrow constructor and its exposed tzinfo behavior, using the Asia/Calcutta examples in the issue. Trace how the timezone is retained and determine how the full Olsen timezone should be retrieved and reused to reconstruct an equivalent Arrow object. Done means the timezone can be serialized and restored without falling back to the IST abbreviation.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
backend
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.