MS_TIME(3)
π NAME π
okay bestie, welcome to MS_TIME(3) from the Library Functions Manual β yes, the whole page is about time, and it's giving Time conversion and string generation energy. No cap.
ms_time - Time conversion and string generation
β¨ SYNOPSIS β¨
here's the include and every single signature, copied character for character because we do not play with prototypes in this house:
#include <libmseed.h>
MS_EPOCH2HPTIME(X) X * (hptime_t) HPTMODULUS
MS_HPTIME2EPOCH(X) X / HPTMODULUS
hptime_t ms_btime2hptime ( BTime *btime );
char *ms_btime2isotimestr ( BTime *btime, char *isotimestr );
char *ms_btime2mdtimestr ( BTime *btime, char *mdtimestr );
char *ms_btime2seedtimestr ( BTime *btime, char *seedtimestr );
int ms_hptime2btime ( hptime_t hptime, BTime *btime );
char *ms_hptime2isotimestr ( hptime_t hptime, char *isotimestr,
flag subseconds );
char *ms_hptime2mdtimestr ( hptime_t hptime, char *mdtimestr,
flag subseconds );
char *ms_hptime2seedtimestr ( hptime_t hptime, char *seedtimestr,
flag subseconds );
hptime_t ms_time2hptime ( int year, int day, int hour, int min,
int sec, int usec );
hptime_t ms_seedtimestr2hptime ( char *seedtimestr );
hptime_t ms_timestr2hptime ( char *timestr );
πΈ DESCRIPTION πΈ
so these routines convert between various time formats. Internally, libmseed represents time values as high precision epoch times (hptime), the number of ticks from the epoch: 00:00:00.00 1 January 1970. By default a tick is defined as a microsecond (0.000001 seconds). See INTERNAL HPTIME below for more details. Also used is the SEED binary time represented by the following data structure (defined in libmseed.h):
typedef struct btime_s
{
uint16_t year; /* year with century */
uint16_t day; /* day, 1 - 366 */
uint8_t hour; /* hour, 0 - 23 */
uint8_t min; /* minute, 0 - 59 */
uint8_t sec; /* second, 0 - 60 (60 = leap second) */
uint8_t unused; /* unused alignment byte */
uint16_t fract; /* fractional seconds, 0 - 9999 */
} BTime;
now the functions and macros, one by one, because we leave no detail behind:
MS_EPOCH2HPTIMEβ a macro that converts a Unix/POSIX epoch time (elapsed seconds since 1 January 1970) to ahptime, and they're related by a simple scaling factor. iconic behavior.MS_HPTIME2EPOCHβ a macro that converts anhptimeto a Unix/POSIX epoch time (elapsed seconds since 1 January 1970), also related by a simple scaling factor. You can cast the result to an integer β in that cast, no rounding is performed and sub-second precision is truncated β or you can cast it into adoubleto get a double precision epoch time. choose your destiny.ms_btime2hptimeβ converts abtimeto ahptime.ms_btime2isotimestrβ generates an ISO recommended format time string from abtime. Example:'2001-07-29T12:38:00.0000'. Theisotimestrmust have enough room for 25 characters. The resulting string will beNULLterminated.ms_btime2mdtimestrβ generates a month-day formatted time string from abtime. Example:'2001-07-29 12:38:00.0000'. Themdtimestrmust have enough room for 25 characters. The resulting string will beNULLterminated.ms_btime2seedtimestrβ generates a SEED format time string from abtime. Example:'2001,195,12:38:00.0000'. Theseedtimestrmust have enough room for 23 characters. The resulting string will beNULLterminated.ms_hptime2btimeβ converts ahptimeto abtime. By default,hptimehas microsecond precision whereas aBTimestructure can only represent time to0.0001seconds. The precision will be lost during this conversion, it will not be accounted for by rounding but will be truncated. This behavior is by design. periodt.ms_hptime2isotimestrβ generates an ISO recommended format time string from ahptime. Example:'2001-07-29T12:38:00.000000'or'2001-07-29T12:38:00'. Theisotimestrmust have enough room for 27 characters. Thesubsecondsflag controls whether the sub-second precision is included or not. The resulting string will beNULLterminated.ms_hptime2mdtimestrβ generates a month-day formatted time string from ahptime. Example:'2001-07-29 12:38:00.000000'or'2001-07-29 12:38:00'. Theisotimestrmust have enough room for 27 characters. Thesubsecondsflag controls whether the sub-second precision is included or not. The resulting string will beNULLterminated.ms_hptime2seedtimestrβ generates a SEED format time string from ahptime. Example:'2001,195,12:38:00.000000'or'2001,195,12:38:00'. Theseedtimestrmust have enough room for 25 characters. Thesubsecondsflag controls whether the sub-second precision is included or not. The resulting string will beNULLterminated.ms_time2hptimeβ converts the time represented by the specifiedyear,day,hour,min,secandusec(microseconds) to anhptime. The range expected for each value is as follows:
year : 1800 - 5000
day : 1 - 366 (366 = last day of leap year)
hour : 0 - 23
min : 0 - 59
sec : 0 - 60 (60 = leap second)
usec : 0 - 999999
NOTE: miniSEED data records are only supported by limbseed with a year range between 1900 and 2100. These routines allow a wider range to support times for metadata, etc.
ms_seedtimestr2hptimeβ converts a SEED time string (day-of-year style) to a high precision epoch time. The time format expected is"YYYY[,DDD,HH,MM,SS.FFFFFF]", the delimiter can be a comma[,], dash[-], colon[:]or period[.]. Additionally a'T'or space may be used to seprate the day and hour fields. The fractional seconds ("FFFFFF") must begin with a period[.]if present.ms_timestr2hptimeβ converts a generic time string to a high precision epoch time. SEED time format is"YYYY[/MM/DD HH:MM:SS.FFFF]", the delimiter can be a dash[-], comma[,], slash[/], colon[:], or period[.]. Additionally a'T'or space may be used between the date and time fields. The fractional seconds ("FFFFFF") must begin with a period[.]if present.
For both ms_seedtimestr2hptime and ms_timestr2hptime the input time string may be "short", in which case the vales omitted on the right hand side are assumed to be 0 (with the exception of month and day which are assumed to be 1). The year is always required. This characteristic means that these time string parsers are very lenient and should not be used for validation or considered to be applying any strict validation. so don't use them as your bouncer, bestie.
π«Ά RETURN VALUES π«Ά
ms_btime2hptime,ms_time2hptime,ms_seedtimestr2hptimeandms_timestr2hptimereturn ahptimeon success andHPTERRORon error.ms_btime2isotimestr,ms_btime2mdtimestr,ms_btime2seedtimestr,ms_hptime2isotimestr,ms_hptime2mdtimestrandms_hptime2seedtimestrreturn a pointer to the resulting string orNULLon error.ms_hptime2btimereturns0on success and-1on error.
π INTERNAL HPTIME π
The time values internal to libmseed are defined as the number of ticks from the epoch: 00:00:00.00 1 January 1970 and often referred to as hptime. By default a tick is defined as a microsecond (0.000001 seconds). The tick interval, and thus hptime precision, is controlled by the definition of HPTMODULUS in libmseed.h. It is not recommended to change HPTMODULUS from the default value of 1000000. like, leave it alone, she's doing great.
This epoch time system is similar to the Unix/POSIX epoch times except that the ticks are higher precision than the 1-second ticks used in POSIX. An hptime can always be converted to a Unix/POSIX epoch time by dividing hptime by HPTMODULUS (reducing the hptime to second precision) and vise-versa, see the documentation for the MS_HPTIME2EPOCH and MS_EPOCH2HPTIME macros above.
As long as the system's gmtime function supports negative epoch times the internal time routines will be able to represent times earlier than the epoch, i.e. times earlier than 1 January 1970. throwback era, literally.
The hptime values are stored as 64-bit integers to allow high precision and avoid accumulation errors associated with floating point values.
A special value defined as HPTERROR in libmseed.h is used to represent errors for routines returning hptime.
π ACKNOWLEDGEMENTS π
With software provided by http://2038bug.com/ (site offline, checked Oct. 2017)
π AUTHOR π
Chad Trabant IRIS Data Management Center
okay bestie, that's the whole page. this absolute icon is from the Libmseed API, dated 2013/02/22, and its manual page name is MS_TIME(3). go forth and convert time, you gorgeous nerd πβ¨π¦π
π¦ where this page comes from
- debian bookworm: libmseed-doc 2.19.8-1 Β· LGPL-3.0-or-later
- debian trixie: libmseed-doc 2.19.8-1 Β· LGPL-3.0-or-later
- fedora 43: libmseed-devel 2.19.5-21.fc43 Β· LGPL-3.0-or-later
- fedora 43: libmseed-devel 2.19.5-21.fc43 Β· LGPL-3.0-or-later
- fedora 44: libmseed-devel 2.19.5-22.fc44 Β· LGPL-3.0-or-later
- fedora 44: libmseed-devel 2.19.5-22.fc44 Β· LGPL-3.0-or-later
- ubuntu jammy: libmseed-doc 2.19.6-3 Β· LGPL-3.0-or-later
- ubuntu noble: libmseed-doc 2.19.8-1ubuntu2 Β· LGPL-3.0-or-later
- ubuntu questing: libmseed-doc 2.19.8-1ubuntu2
- ubuntu resolute: libmseed-doc 2.19.8-1ubuntu3 Β· LGPL-3.0-or-later
- ubuntu stonking: libmseed-doc 2.19.8-1ubuntu3 Β· LGPL-3.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms