question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Contructor issue with non-None timezone

See original GitHub issue

Constructor of Arrow object (arrow.py) fails if tzinfo is non-None and if it does not contain field “zone”.

The problematic part:

            isinstance(tzinfo, dt_tzinfo)
            and hasattr(tzinfo, "localize")
            and tzinfo.zone
        ):

should be like

            isinstance(tzinfo, dt_tzinfo)
            and hasattr(tzinfo, "localize")
            and hasattr(tzinfo, "zone")
        ):

The change came since version 0.14.5

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
mafycekcommented, Sep 9, 2019

Hi guys, hope that you are well. Say, I have a (simple) program like:

import arrow
import dateparser

date_that_succeds = "1990-01-01T00:00:00"
date_that_fails = "1990-01-01T00:00:00+00:00"

for date in [date_that_succeds, date_that_fails]:
    try:
        parsed_date = dateparser.parse(date, date_formats=None or ['%d %B %Y', '%d/%m/%y', '%d/%m/%Y', '%d.%m.%Y'])
        arrow_date = arrow.get(parsed_date)
        print(date_that_succeded, arrow_date)
    except:
        print("It failed on date " + date)

Results: with arrow 0.15.0 (since 0.14.5) The first date passes however the the second fails. with arrow 0.14.4 (I tested on 0.13.1) Both pass

Explanation of the failure: parsed_date is of type datetime with component variable tzinfo of type StaticTzInfo. The StaticTzInfo type has two component variables _StaticTzInfo__name of type str and _StaticTzInfo__offset of type timedelta. When such variable is inserted into arrow through get it fails in the constructor of arrow class because tzinfo in the constructor is of type StaticTzInfo that does not have component variable zone and that is why the interpreter says AttributeError: ‘StaticTzInfo’ object has no attribute ‘zone’

My comment: I do not know if the test of zone component is correct. If yes that it should test presence of the variable and then the value if that is needed.

Regression for this case would be really needed. Well, it could test more that one timezone and take into account some special ones with non-integer shifts.

Bye, Hynek

0reactions
systemcatchcommented, Sep 10, 2019

Thanks @mafycek, we will do some digging on this bug and look at fixes.

Useful note, you can wrap python code blocks like this.

```python INSERT BUG HERE ```

Read more comments on GitHub >

github_iconTop Results From Across the Web

Weird timezone issue with pytz - python - Stack Overflow
When you use localize to attach the zone to a date, the proper zone name and offset are substituted. Simply using the datetime...
Read more >
pd.Timestamp constructor ignores missing arguments #31930
The constructor argument-handling behavior is a problem. I, however, disagree that constructing timezone-aware Timestamps should happen in two ...
Read more >
TimeZone (Java Platform SE 7 ) - Oracle Help Center
Returns the amount of time in milliseconds to add to UTC to get standard time in this time zone. Because this value is...
Read more >
datetime — Basic date and time types — Python 3.11.1 ...
Date and time objects may be categorized as “aware” or “naive” depending on whether or not they include timezone information.
Read more >
Working with dates and timezones in JavaScript - Ursa Health
Nor are date and timezone problems the sort of issue that a great library can ... The timezone that Dave Jorgenson happened to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found