Skip to content

Commit

Permalink
Merge pull request #6 from JuliaGeo/splittimezone
Browse files Browse the repository at this point in the history
Split time zone info if it is given
  • Loading branch information
Alexander-Barth authored Feb 19, 2020
2 parents 56bd733 + 4b38a98 commit 4236a50
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/CFTime.jl
Original file line number Diff line number Diff line change
Expand Up @@ -503,9 +503,20 @@ function parseDT(::Type{DT},str) where DT <: Union{DateTime,AbstractCFDateTime}
(y,m,d,h,mi,s,Int64(0))
=#
timestr,tz = if occursin("+",timestr)
ts,tz = split(timestr,"+")
ts,tz
elseif occursin("-",timestr)
ts,tz = split(timestr,"-")
ts,string("-",tz)
else
timestr, "00:00"
end
if !all(iszero(parse.(Int,split(tz,":"))))
@warn "Time zones are currently not supported by CFTime. Ignoring Time zone information: $(tz)"
end

time_split = split(timestr,':')

h_str, mi_str, s_str =
if length(time_split) == 2
time_split[1], time_split[2], "00"
Expand All @@ -516,7 +527,6 @@ function parseDT(::Type{DT},str) where DT <: Union{DateTime,AbstractCFDateTime}

h = parse(Int64,h_str)
mi = parse(Int64,mi_str)

s,ms =
if occursin('.',s_str)
# seconds contain a decimal point, e.g. 00:00:00.0
Expand Down
22 changes: 22 additions & 0 deletions test/test_time.jl
Original file line number Diff line number Diff line change
Expand Up @@ -420,3 +420,25 @@ data = [0,1,2,3]
dt = CFTime.timedecode(DateTime360Day,data,"days since 2000-01-01 00:00:00")
data2 = CFTime.timeencode(dt,"days since 2000-01-01 00:00:00",DateTime360Day)
@test data == data2

#issue #6

data = [0,1,2,3]
dt = CFTime.timedecode(DateTime,data,"days since 2000-01-01 00:00:00+00")
data2 = CFTime.timeencode(dt,"days since 2000-01-01 00:00:00+00",DateTime)
@test data == data2

data = [0,1,2,3]
dt = CFTime.timedecode(DateTime360Day,data,"days since 2000-01-01 00:00:00+00:00")
data2 = CFTime.timeencode(dt,"days since 2000-01-01 00:00:00+00:00",DateTime360Day)
@test data == data2

data = [0,1,2,3]
dt = CFTime.timedecode(DateTime,data,"days since 2000-01-01 00:00:00+01")
data2 = CFTime.timeencode(dt,"days since 2000-01-01 00:00:00+00",DateTime)
@test data == data2

data = [0,1,2,3]
dt = CFTime.timedecode(DateTime360Day,data,"days since 2000-01-01 00:00:00-01:00")
data2 = CFTime.timeencode(dt,"days since 2000-01-01 00:00:00+00:00",DateTime360Day)
@test data == data2

0 comments on commit 4236a50

Please sign in to comment.