CFTime
CFTime
encodes and decodes time units conforming to the Climate and Forecasting (CF) netCDF conventions.
CFTime
was split out of the NCDatasets julia package.
Installation
Inside the Julia shell, you can download and install the package by issuing:
using Pkg
Pkg.add("CFTime")
Example
using CFTime, Dates
# standard calendar
dt = CFTime.timedecode([0,1,2,3],"days since 2000-01-01 00:00:00")
# 4-element Array{Dates.DateTime,1}:
# 2000-01-01T00:00:00
# 2000-01-02T00:00:00
# 2000-01-03T00:00:00
# 2000-01-04T00:00:00
CFTime.timeencode(dt,"days since 2000-01-01 00:00:00")
# 4-element Array{Float64,1}:
# 0.0
# 1.0
# 2.0
# 3.0
# "360 day" calendar
dt = CFTime.timedecode([0,1,2,3],"days since 2000-01-01 00:00:00",DateTime360Day)
# 4-element Array{DateTime360Day,1}:
# DateTime360Day(2000-01-01T00:00:00)
# DateTime360Day(2000-01-02T00:00:00)
# DateTime360Day(2000-01-03T00:00:00)
# DateTime360Day(2000-01-04T00:00:00)
dt[2]-dt[1]
# 86400000 milliseconds
Dates.Day(dt[2]-dt[1])
# 1 day
CFTime.timeencode(dt,"days since 2000-01-01 00:00:00",DateTime360Day)
# 4-element Array{Float64,1}:
# 0.0
# 1.0
# 2.0
# 3.0
DateTime360Day(2000,1,1) + Dates.Day(360)
# DateTime360Day(2001-01-01T00:00:00)
You can replace in the example above the type DateTime360Day
by the string "360_day"
(the name according to the CF conversion).