Skip to content
This repository was archived by the owner on Sep 1, 2022. It is now read-only.
This repository was archived by the owner on Sep 1, 2022. It is now read-only.

Date truncated by cast to long #1355

Open
@mdtdhi

Description

@mdtdhi

Using netcdfAll-4.6.16.1 java library.

I've encountered multiple NetCDF files where the date is truncated by a second in DateUnit.makeStandardDateString(double). The implementation in 4.6.16.1 results in a date string with second precision, but I believe the date is only truncated by a millisecond.

i.e. secs = 89999.999999999985 is incorrectly rounded down to 89999999 milliseconds.

see /cdm/core/src/main/java/ucar/nc2/units/DateUnit.java
getDate (line 191)
makeDate (line 213):
return new Date(getDateOrigin().getTime() + (long) (1000 * secs));

Rounding prior to casting should solve the issue. Something like:
return new Date(getDateOrigin().getTime() + (long) Math.Round(1000 * secs));

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions