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

So how do I use this thing? #1

Closed
jiahao opened this issue Mar 9, 2015 · 32 comments
Closed

So how do I use this thing? #1

jiahao opened this issue Mar 9, 2015 · 32 comments

Comments

@jiahao
Copy link

jiahao commented Mar 9, 2015

I have DateTime data which comes with extra fields indicating the time zone in offsets from UTC and whether daylight saving is on. How do I construct a timezone-aware DateTime-like object?

@quinnj
Copy link
Collaborator

quinnj commented Mar 10, 2015

The day of reckoning has come. Guess I better get this package in shape. Honestly I haven't touched it since I moved it out of the Dates module last summer. I was going to work on JuliaLang/julia#8718 first, but I guess I can get this up and running beforehand. I don't think there's a ton of work I need to do, but let me dig into it over the next few days.

@gragusa
Copy link

gragusa commented Mar 10, 2015

+1

I have to handle a large high frequency data project and I can be a good beta tester of the implementation of DataTime + TimeZones.

@jiahao
Copy link
Author

jiahao commented Mar 10, 2015

The danger of writing code is that someone might actually try to use it. ;-)

@StefanKarpinski
Copy link

@quinnj – would be great to have some docs for this; I'm finding myself need it. Let me know if there's anything I can do to help.

@quinnj
Copy link
Collaborator

quinnj commented Mar 11, 2015

Alright, alright, I'll do it :) Thankfully most of the dirty work is done and it's mainly designing the interface. You should at least be able to do

Pkg.clone("https://github.com/quinnj/TimeZones.jl")
Pkg.build("TimeZones")

as of now. I'll open up another issue where peeps can chime in on desired interface (we're starting from scratch here, so I'd appreciate any input).

@szalmaf
Copy link

szalmaf commented Sep 1, 2015

Any progress on this issue? It'd be great to be able to use this package. I am working on a project that badly needs timezoned datetime and if it does not work yet in Julia, I need to fall back to R.

I just tried the Warsaw example and it is broken:

warsaw = TimeZone("Europe/Warsaw")
ZonedDateTime(DateTime(2014,1,1), warsaw)

LoadError: Unknown timezone Europe/Warsaw
while loading In[60], in expression starting on line 1

in call at /Users/szf/.julia/v0.4/TimeZones/src/TimeZones.jl:33

Any suggestion is welcome as to how to get it running.

@quinnj
Copy link
Collaborator

quinnj commented Sep 1, 2015

What's the output of running

Pkg.clone("https://github.com/quinnj/TimeZones.jl")
Pkg.build("TimeZones")

?

@szalmaf
Copy link

szalmaf commented Sep 1, 2015

Pkg.clone("https://github.com/quinnj/TimeZones.jl")

INFO: Cloning TimeZones from https://github.com/quinnj/TimeZones.jl
LoadError: TimeZones already exists
while loading In[61], in expression starting on line 1

Pkg.build("TimeZones")
INFO: Building TimeZones
INFO: Downloading TZ data
% % Total % Total % Re % Tot a l% T o % TReocteailv e d %% XRfeecred iAvveedr a%g eX fSeprededc % t%a l T eAvie rT oo%a v tRge e t T% iRmeec e i vaed eal c S%lp Td i e m%e e d % iX fv e XTe % d f Tieme errRdCide m u cA%ve rXafg eeei vSpReeee drArre n t
T ivmeer a g e T di mecS e T ipm e d i%ev e d X%f eXrfde r dA Aevv e d e eAr avrear T g a g eg eTi mSep e eCduT i Sr e S irpme e dp e Tmie e nte
Timmee e d T i C T i m e T i D m u Timmee Teime r l o a CdT u rUprl Trioe n t
T i me mCiameun tee d C u r r
T rr e o tna t e l
T i m S e p ne C un t r tr
e nLte
ft S p D e e d
0 o 0 a d DD l o aUdp 0l o l o a d U p lad 0 o U Tpolt aaod l TDolt a lS 0 Dolp eandt T oLteaflt SSppeeendt
t o ad U p lDoloa d U p0l o ad T0o tal Spent ad Sp0e ed ad L e f t
00 00 00 S0 p e n t0 L e0f t S p e0e d

  • - :0 --:--:-- --:--:-- --:----:d- 0 Speed
    0 0 0 0 :-- -- Total Spent Left Speed
    0 Total S pe n0t 0L ef : 0- - :t Spee 0 d0 - - - --:0--:-0
    100 13018 100 13018 0 0 7932 0 0:00:01 0:00:01 --:--:-- 7937
    100 48014 100 48014 0 0 28792 0 0:00:01 0:00:01 --:--:-- 28802
    100 121k 100 121k 0 0 57532 0 0:00:02 0:00:02 --:--:-- 57550
    100 72533 100 72533 0 0 31500 0 0:00:02 0:00:02 --:--:-- 31508
    100 76319 100 76319 0 0 32108 0 0:00:02 0:00:02 --:--:-- 32120
    100 136k 100 136k 0 0 56558 0 0:00:02 0:00:02 --:--:-- 56572
    100 140k 100 140k 0 0 52662 0 0:00:02 0:00:02 --:--:-- 52659
    INFO: Pre-processing TimeZone data
    ==============================[ ERROR: TimeZones ]==============================

LoadError: MethodError: convert has no method matching convert(::Type{Base.Dates.DelimitedSlot{T}}, ::Int64, ::Type{Base.Dates.Year}, ::Int64, ::Int64, ::ASCIIString)
This may have arisen from a call to the constructor Base.Dates.DelimitedSlot{T}(...),
since type constructors fall back to convert methods.
Closest candidates are:
Base.Dates.DelimitedSlot{T}(!Matched::Type{T}, !Matched::Char, ::Int64, !Matched::Union{AbstractString,Regex})
call{T}(::Type{T}, ::Any)
convert{T}(::Type{T}, !Matched::T)
while loading /Users/szf/.julia/v0.4/TimeZones/deps/build.jl, in expression starting on line 43

================================[ BUILD ERRORS ]================================

WARNING: TimeZones had build errors.

  • packages with build errors remain installed in /Users/szf/.julia/v0.4
  • build the package(s) and all dependencies with Pkg.build("TimeZones")
  • build a single package by running its deps/build.jl script

@quinnj
Copy link
Collaborator

quinnj commented Sep 1, 2015

@omus, do we need a fix in TimeZones after JuliaLang/julia#12799 was merged?

@szalmaf
Copy link

szalmaf commented Sep 1, 2015

And I am using Julia v0.4, but the package is only for the 0.4 version anyway, right?

@quinnj
Copy link
Collaborator

quinnj commented Sep 1, 2015

I believe so yes. Are you using a very recent 0.4 master? Like, compiled within the last week? We just merged some changes to 0.4 master that will make TimeZones a little better to work with and I think it may have broken the package here.

@szalmaf
Copy link

szalmaf commented Sep 1, 2015

Yes, I downloaded and installed v0.4 a few days ago.

@szalmaf
Copy link

szalmaf commented Sep 1, 2015

For completeness:

using TimeZones

gives these warnings

WARNING: module TimeZones should explicitly import == from Base
WARNING: module TimeZones should explicitly import + from Base
WARNING: module TimeZones should explicitly import - from Base
WARNING: module TimeZones should explicitly import + from Base
WARNING: module TimeZones should explicitly import + from Base
WARNING: module TimeZones should explicitly import - from Base
WARNING: module TimeZones should explicitly import - from Base
WARNING: Method definition call(Type{Base.Dates.DateFormat}, AbstractString) in module Dates at dates/io.jl:86 overwritten in module TimeZones at /Users/szalmaf/.julia/v0.4/TimeZones/src/timezones/io.jl:63.
WARNING: Method definition call(Type{Base.Dates.DateFormat}, AbstractString, AbstractString) in module Dates at dates/io.jl:86 overwritten in module TimeZones at /Users/szalmaf/.julia/v0.4/TimeZones/src/timezones/io.jl:63.
WARNING: Method definition parse(AbstractString, Base.Dates.DateFormat) in module Dates at dates/io.jl:148 overwritten in module TimeZones at /Users/szalmaf/.julia/v0.4/TimeZones/src/timezones/io.jl:85.
WARNING: Method definition lastdayofyear(Base.Dates.DateTime) in module Dates at dates/adjusters.jl:42 overwritten in module TimeZones at /Users/szalmaf/.julia/v0.4/TimeZones/src/timezones/adjusters.jl:17.

which is a bit scary.

@omus
Copy link
Member

omus commented Sep 1, 2015

@quinnj we just need to merge in #5. I was going to double check it and merge it tomorrow. Once merged TimeZones shouldn't have any more warnings about overwritten methods. I guess I should make another release as the current Julia v0.4 doesn't work with the existing release.

@omus
Copy link
Member

omus commented Sep 1, 2015

@szalmaf if you want to use the package right now you can do Pkg.checkout("TimeZones", "parsing") then Pkg.build("TimeZones"). You'll get the warnings about the explicit imports but the scary warnings should be gone.

@szalmaf
Copy link

szalmaf commented Sep 1, 2015

@omus OK, I just tried the Pkg.checkout("TimeZones", "parsing") then Pkg.build("TimeZones") and it still has problems building the package:

Pkg.checkout("TimeZones", "parsing")

INFO: Checking out TimeZones parsing...
INFO: Pulling TimeZones latest parsing...
INFO: No packages to install, update or remove

Pkg.build("TimeZones")

INFO: Building TimeZones
INFO: Downloading TZ data
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0 % Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0 % Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0 % Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0 % Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0 % Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0 % Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 13018 100 13018 0 0 8404 0 0:00:01 0:00:01 --:--:-- 8409
100 48014 100 48014 0 0 29272 0 0:00:01 0:00:01 --:--:-- 29258
100 76319 100 76319 0 0 35845 0 0:00:02 0:00:02 --:--:-- 35847
100 72533 100 72533 0 0 31388 0 0:00:02 0:00:02 --:--:-- 31399
100 121k 100 121k 0 0 53250 0 0:00:02 0:00:02 --:--:-- 53254
100 136k 100 136k 0 0 59901 0 0:00:02 0:00:02 --:--:-- 59924
100 140k 100 140k 0 0 55246 0 0:00:02 0:00:02 --:--:-- 55226
INFO: Pre-processing TimeZone data
==============================[ ERROR: TimeZones ]==============================

LoadError: MethodError: convert has no method matching convert(::Type{Base.Dates.DelimitedSlot{T}}, ::Int64, ::Type{Base.Dates.Year}, ::Int64, ::Int64, ::ASCIIString)
This may have arisen from a call to the constructor Base.Dates.DelimitedSlot{T}(...),
since type constructors fall back to convert methods.
Closest candidates are:
Base.Dates.DelimitedSlot{T}(!Matched::Type{T}, !Matched::Char, ::Int64, !Matched::Union{AbstractString,Regex})
call{T}(::Type{T}, ::Any)
convert{T}(::Type{T}, !Matched::T)
while loading /Users/szalmaf/.julia/v0.4/TimeZones/deps/build.jl, in expression starting on line 43

================================[ BUILD ERRORS ]================================

WARNING: TimeZones had build errors.

  • packages with build errors remain installed in /Users/szalmaf/.julia/v0.4
  • build the package(s) and all dependencies with Pkg.build("TimeZones")
  • build a single package by running its deps/build.jl script

@omus
Copy link
Member

omus commented Sep 1, 2015

@szalmaf can you let me know the output of versioninfo()?

@szalmaf
Copy link

szalmaf commented Sep 1, 2015

versioninfo()

Julia Version 0.4.0-pre+7105
Commit 349a4e1 (2015-08-30 15:16 UTC)
Platform Info:
System: Darwin (x86_64-apple-darwin13.4.0)
CPU: Intel(R) Core(TM) i7-2760QM CPU @ 2.40GHz
WORD_SIZE: 64
BLAS: libopenblas (USE64BITINT DYNAMIC_ARCH NO_AFFINITY Sandybridge)
LAPACK: libopenblas
LIBM: libopenlibm
LLVM: libLLVM-3.3

@omus
Copy link
Member

omus commented Sep 1, 2015

@szalmaf I'm having difficulties reproducing the error you are getting. Can you run import TimeZones; TimeZones.Olsen.compile()?

@szalmaf
Copy link

szalmaf commented Sep 1, 2015

import TimeZones; TimeZones.Olsen.compile()

LoadError: MethodError: convert has no method matching convert(::Type{Base.Dates.DelimitedSlot{T}}, ::Int64, ::Type{Base.Dates.Year}, ::Int64, ::Int64, ::ASCIIString)
This may have arisen from a call to the constructor Base.Dates.DelimitedSlot{T}(...),
since type constructors fall back to convert methods.
Closest candidates are:
Base.Dates.DelimitedSlot{T}(!Matched::Type{T}, !Matched::Char, ::Int64, !Matched::Union{AbstractString,Regex})
call{T}(::Type{T}, ::Any)
convert{T}(::Type{T}, !Matched::T)
while loading In[17], in expression starting on line 1

in call at essentials.jl:58
in call at /Users/szalmaf/.julia/v0.4/TimeZones/src/timezones/io.jl:76
in call at /Users/szalmaf/.julia/v0.4/TimeZones/src/timezones/io.jl:63
in parsedate at /Users/szalmaf/.julia/v0.4/TimeZones/src/timezones/Olsen.jl:108
in zoneparse at /Users/szalmaf/.julia/v0.4/TimeZones/src/timezones/Olsen.jl:205
in anonymous at /Users/szalmaf/.julia/v0.4/TimeZones/src/timezones/Olsen.jl:459
in open at iostream.jl:114
in tzparse at /Users/szalmaf/.julia/v0.4/TimeZones/src/timezones/Olsen.jl:440
in load at /Users/szalmaf/.julia/v0.4/TimeZones/src/timezones/Olsen.jl:483
in compile at /Users/szalmaf/.julia/v0.4/TimeZones/src/timezones/Olsen.jl:490 (repeats 2 times)

@omus
Copy link
Member

omus commented Sep 1, 2015

Thanks. Ok it appears you are still running the old version of the package. Try running Pkg.checkout("TimeZones", "parsing") which should get you the working version. You can confirm that Julia updated the package via Pkg.status("TimeZones"). This issue will go away once I merge #5.

@szalmaf
Copy link

szalmaf commented Sep 1, 2015

After doing

Pkg.checkout("TimeZones", "parsing")

the

Pkg.status("TimeZones")

gives

  • TimeZones 0.0.1+ parsing

Is this 0.0.1+ the right version? Also, I didn't build it this time. Should I?

@omus
Copy link
Member

omus commented Sep 1, 2015

@szalmaf that is the right version. You should be able to run Pkg.build("TimeZones") now without running into an exception.

@szalmaf
Copy link

szalmaf commented Sep 1, 2015

Pkg.build("TimeZones")

still produces this:

INFO: Building TimeZones
INFO: Downloading TZ data
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0 % Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0 % Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0 % Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0 % Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0 % Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0 % Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 0 -0- :- - : - -0 - - : - - :0- - - - : -0- :----: - - : - -0 --:--:-- --:--:-- 0curl: (56) Recv failure: Connection reset by peer
curl: (56) Recv failure: Connection reset by peer
curl: (56) Recv failure: Connection reset by peer
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0 % Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0 % Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 13018 100 13018 0 0 10225 0 0:00:01 0:00:01 --:--:-- 10234
100 48014 100 48014 0 0 36157 0 0:00:01 0:00:01 --:--:-- 36182
100 76319 100 76319 0 0 39904 0 0:00:01 0:00:01 --:--:-- 39894
100 72533 100 72533 0 0 36922 0 0:00:01 0:00:01 --:--:-- 36912
100 121k 100 121k 0 0 60072 0 0:00:02 0:00:02 --:--:-- 60085
100 136k 100 136k 0 0 69179 0 0:00:02 0:00:02 --:--:-- 69194
100 140k 100 140k 0 0 57814 0 0:00:02 0:00:02 --:--:-- 57800
INFO: Pre-processing TimeZone data
==============================[ ERROR: TimeZones ]==============================

LoadError: MethodError: convert has no method matching convert(::Type{Base.Dates.DelimitedSlot{T}}, ::Int64, ::Type{Base.Dates.Year}, ::Int64, ::Int64, ::ASCIIString)
This may have arisen from a call to the constructor Base.Dates.DelimitedSlot{T}(...),
since type constructors fall back to convert methods.
Closest candidates are:
Base.Dates.DelimitedSlot{T}(!Matched::Type{T}, !Matched::Char, ::Int64, !Matched::Union{AbstractString,Regex})
call{T}(::Type{T}, ::Any)
convert{T}(::Type{T}, !Matched::T)
while loading /Users/szalmaf/.julia/v0.4/TimeZones/deps/build.jl, in expression starting on line 43

================================[ BUILD ERRORS ]================================

WARNING: TimeZones had build errors.

  • packages with build errors remain installed in /Users/szalmaf/.julia/v0.4
  • build the package(s) and all dependencies with Pkg.build("TimeZones")
  • build a single package by running its deps/build.jl script

@omus
Copy link
Member

omus commented Sep 1, 2015

I'll just get this new release out. This is strange as the exception you are getting would be from running an older version of the code.

@szalmaf
Copy link

szalmaf commented Sep 1, 2015

I restarted the 0.4 kernel in Jupyter and built TimeZones again, and it seems like it helped:

Pkg.build("TimeZones")

INFO: Building TimeZones
WARNING: module TimeZones should explicitly import == from Base
WARNING: module TimeZones should explicitly import + from Base
WARNING: module TimeZones should explicitly import - from Base
WARNING: module TimeZones should explicitly import + from Base
WARNING: module TimeZones should explicitly import + from Base
WARNING: module TimeZones should explicitly import - from Base
WARNING: module TimeZones should explicitly import - from Base
INFO: Downloading TZ data
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0 % Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0 % Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0 % Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0 % Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0 % Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0 % Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 48014 100 48014 0 0 33044 0 0:00:01 0:00:01 --:--:-- 33067
100 13018 100 13018 0 0 8722 0 0:00:01 0:00:01 --:--:-- 8725
100 76319 100 76319 0 0 37178 0 0:00:02 0:00:02 --:--:-- 37192
100 72533 100 72533 0 0 33199 0 0:00:02 0:00:02 --:--:-- 33211
100 121k 100 121k 0 0 56517 0 0:00:02 0:00:02 --:--:-- 56528
100 140k 100 140k 0 0 63166 0 0:00:02 0:00:02 --:--:-- 63182
100 136k 100 136k 0 0 57585 0 0:00:02 0:00:02 --:--:-- 57600
INFO: Pre-processing TimeZone data
INFO: Successfully processed TimeZone data

@omus
Copy link
Member

omus commented Sep 1, 2015

Awesome. Everything should work as intended now. I'll get this fixed today so that others don't run into the same issue.

@szalmaf
Copy link

szalmaf commented Sep 1, 2015

Great. Thanks for your help.

Just a quick check:

warsaw = TimeZone("Europe/Warsaw")
ZonedDateTime(DateTime(2014,1,1), warsaw)

now outputs

2014-01-01T00:00:00+01:00

@omus
Copy link
Member

omus commented Sep 1, 2015

Working as intended. Check out the README for a basic usage walkthrough.

@szalmaf
Copy link

szalmaf commented Sep 1, 2015

Wouldn't it be a good idea to have in core a DateTime constructor signature corresponding to DateTime(2014,1,1, warsaw) (also extended to h, m, s, etc.) instead of writing ZonedDateTime(DateTime(2014,1,1), warsaw)? Just a suggestion.

@omus
Copy link
Member

omus commented Sep 2, 2015

There are plenty of features to be added including convenience constructors. I've updated the package to work with the Julia v0.4-pre release. The updated version of TimeZones just needs be merged into METADATA. JuliaLang/METADATA.jl#3257

@omus
Copy link
Member

omus commented Sep 2, 2015

Closing issue as basic usage has been addressed in the README.

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

6 participants