Skip to content

Incorrect ISO timestamp formatting in some cases #151

Description

@valeriy-sokoloff

Test:

#include <stdio.h>
#include "novas.h"

int main() {
    long test_values[3] = {1748314880, 1752799060, 1755929180};
    
    novas_timespec ts;
    char iso_timestamp[40];
    
    for (int i = 0; i < 3; i++) {
        long unixtime = test_values[i];
        
        novas_set_unix_time(unixtime, 0, 0.0, 0.0, &ts) != 0;
        
        novas_iso_timestamp(&ts, iso_timestamp, sizeof(iso_timestamp));
      
        double jd = novas_get_time(&ts, NOVAS_UTC);

        printf("%ld | %17.10f | %s\n", unixtime, jd, iso_timestamp);
    }
    
    return 0;
}

Output:

$ ./example-unixtime 
1748314880 | 2460822.6259259260 | 2025-05-27T03:01:110.000Z
1752799060 | 2460874.5261574076 | 2025-07-18T00:37:310.000Z
1755929180 | 2460910.7543981480 | 2025-08-23T06:06:110.000Z

Looks like, due to floating-point calculations, s at some point (L1007) becomes 19.9(9) or 39.9(9) instead of 20 or 40, which produces incorrect seconds value in the resulting timestamp:
https://github.com/Smithsonian/SuperNOVAS/blob/c2449e1cae2d14a0c37379cb0d515d4e201c82fb/src/timescale.c#L1001-L1007

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No fields configured for Bug.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions