Skip to content

Commit

Permalink
Fixed parsing of dates in NetCDF files
Browse files Browse the repository at this point in the history
This release fixes an issue with reading NetCDF files that have `date`
as a time dimension. Only the YYYYMMDD format is currently supported.
  • Loading branch information
Sbozzolo committed Oct 25, 2024
1 parent 5e0d1fa commit 584cff2
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
7 changes: 7 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ downstream packages where `ActiveLinkStyle` had to be imported just to call

The old signature was deprecated.

### Bug fixes

#### Fixed parsing of `date`s in NetCDF files. PR [#122](https://github.com/CliMA/ClimaUtilities.jl/pull/122)

This release fixes an issue with reading NetCDF files that have `date` as a time
dimension. Only the YYYYMMDD format is currently supported.

v0.1.16
------

Expand Down
19 changes: 18 additions & 1 deletion ext/nc_common.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,25 @@ function read_available_dates(ds::NCDatasets.NCDataset)
reinterpret.(Ref(NCDatasets.DateTimeStandard), ds["time"][:])
)
elseif "date" in keys(ds.dim)
return strdate_to_datetime.(string.(ds["date"][:]))
return yyyymmdd_to_datetime.(string.(ds["date"][:]))
else
return Dates.DateTime[]
end
end

"""
strdate_to_datetime(strdate::String)
Convert from String ("YYYYMMDD") to Date format.
# Arguments
- `yyyymmdd`: [String] to be converted to Date type
"""
function yyyymmdd_to_datetime(strdate::String)
length(strdate) == 8 || error("$strdate does not have the YYYYMMDD format")
return Dates.DateTime(
parse(Int, strdate[1:4]),
parse(Int, strdate[5:6]),
parse(Int, strdate[7:8]),
)
end

0 comments on commit 584cff2

Please sign in to comment.