-
Notifications
You must be signed in to change notification settings - Fork 179
Date truncated by cast to long #1355
Comments
Do you have an example file that you could share that triggers this issue? |
See attached. Date time should be 2021-02-27 01:00:00. Result is 2021-02-27 00:59:59. |
Date time should be 2021-02-27 01:00:00.
Which exact Date time in the example file are you referring to?
…On Mon, Mar 1, 2021 at 5:15 PM mdtdhi ***@***.***> wrote:
Do you have an example file that you could share that triggers this issue?
See attached.
Date time should be 2021-02-27 01:00:00. Result is 2021-02-27 12:59:59.
IDY25402.APS3.group2.slv.2021022600.025.surface.zip
<https://github.com/Unidata/netcdf-java/files/6065225/IDY25402.APS3.group2.slv.2021022600.025.surface.zip>
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<https://github.com/Unidata/netcdf-java/issues/620#issuecomment-788421838>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAEVZQBYI4WU56NGVQIMIIDTBQU3TANCNFSM4YL3YWOA>
.
|
Which exact Date time in the example file are you referring to? |
I dont see the problem in versions 5 and 6, though I dont have a particular field to check. |
Variable: 'time' Attributes: |
version 6:
days since 2021-02-26 00:00:00 (-0.020833, 1.041667) == (2021-02-25T23:30:00Z, 2021-02-27T01:00:00Z) |
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));
The text was updated successfully, but these errors were encountered: