Skip to content

Commit 103a11a

Browse files
With ms_nstime2timestr_n() print "ERROR" for NSTERROR and "UNSET" for NSTUNSET
1 parent 20bda1e commit 103a11a

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed

ChangeLog

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
2025.233:
22
- Add ms_nstime2timestr_n() with string size limit, deprecate ms_nstime2timestr().
3+
- With ms_nstime2timestr_n() print "ERROR" for NSTERROR and "UNSET" for NSTUNSET.
34

45
2025.227:
56
- Properly round negative values when converting floats to integers

genutils.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1005,6 +1005,18 @@ ms_nstime2timestr_n (nstime_t nstime, char *timestr, size_t timestrsize,
10051005
return NULL;
10061006
}
10071007

1008+
if (nstime == NSTERROR)
1009+
{
1010+
snprintf (timestr, timestrsize, "ERROR");
1011+
return timestr;
1012+
}
1013+
1014+
if (nstime == NSTUNSET)
1015+
{
1016+
snprintf (timestr, timestrsize, "UNSET");
1017+
return timestr;
1018+
}
1019+
10081020
/* Reduce to Unix/POSIX epoch time and fractional nanoseconds */
10091021
isec = rawisec = MS_NSTIME2EPOCH (nstime);
10101022
nanosec = rawnanosec = (int)(nstime - (isec * NSTMODULUS));

test/test-time.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#include <libmseed.h>
33
#include <time.h>
44

5-
TEST (time, nstime)
5+
TEST (time, nstime2timestr)
66
{
77
char timestr[50];
88
nstime_t nstime;
@@ -71,7 +71,18 @@ TEST (time, nstime)
7171
ms_nstime2timestr_n (nstime, timestr, sizeof(timestr), ISOMONTHDAY_Z, MICRO_NONE);
7272
CHECK_STREQ (timestr, "2004-05-12T07:08:09Z");
7373

74-
/* Time string variations */
74+
/* Unset time */
75+
ms_nstime2timestr_n (NSTUNSET, timestr, sizeof(timestr), ISOMONTHDAY_Z, NANO_MICRO_NONE);
76+
CHECK_STREQ (timestr, "UNSET");
77+
78+
/* Error time */
79+
ms_nstime2timestr_n (NSTERROR, timestr, sizeof(timestr), ISOMONTHDAY_Z, NANO_MICRO_NONE);
80+
CHECK_STREQ (timestr, "ERROR");
81+
}
82+
83+
TEST (time, timestr2nstime)
84+
{
85+
nstime_t nstime;
7586

7687
nstime = ms_timestr2nstime ("2004");
7788
CHECK (nstime == 1072915200000000000, "Failed to convert time string: '2004'");

0 commit comments

Comments
 (0)