Replies: 1 comment
-
I also noted this comment, which I totally agree with:
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi,
I just recently started looking into Arrow, and I like it.
However, I am having a little difficulty trying to get my head around solving my issue with timezones.
The problem I am facing is that I want to parse times from strings that might, or might not contain timezone information (user input and external APIs), and I would like them to end up in local timezone. This also means that any naïve times should be parsed as local (default to use local timezone).
To illustrate I will use the following examples:
In the first two examples I am not able to differentiate the inputs because UTC is used as a default. As I want the output to be in local timezone I tried to set
tzinfo="local"
, which works as expected for any input that does not contain timezone information, as seen in the third example. If the input contains timezone information, however, this actually replaces the tzinfo instead of converting the time, seen in example four. So, to get the correct time with an input containing timezone information I must use theto()
method as seen in the last exmaple, and for naive inputs I have to use thetzinfo
parameter.Currently I cannot see that an Arrow object contains information about the input being naïve (if the default UTC timezone has been used), or the possibility to chose a default timezone to use for naïve inputs. I believe that both of these options would be nice to have, but I am open to any other suggestions to solving my problem.
For the first idea, it might be possible to add an attribute to the Arrow object that indicates if the default timezone has been used, which could be possible to set within this if statement:
arrow/arrow/arrow.py
Lines 323 to 325 in f8a6521
The second idea I guess would mean adding a new parameter to the
get()
method, such asdefault_tz
or similar, that is passed on for usage in the same spot.I will try to illustrate the ideas I am proposing:
As seen in the first two illustrations, any naïve input will use the default_tz, while any existing timezone information from input is used.
With this functionality I am able to use the same logic for all my inputs, as seen in the last three illustrations.
Thank you very much!
Beta Was this translation helpful? Give feedback.
All reactions