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 INTERNALHPTIME 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;
MS_EPOCH2HPTIME is a macro which converts a Unix/POSIX epoch time (elapsed seconds since 1 January 1970)
to a hptime which are related by a simple scaling factor.
MS_HPTIME2EPOCH is a macro which converts an hptime to a Unix/POSIX epoch time (elapsed seconds since 1
January 1970) which are related by a simple scaling factor. The result can be cast to an integer, in
which cast no rounding is performed and sub-second precision is truncated, or can be cast into a double
to get a double precision epoch time.
ms_btime2hptime converts a btime to a hptime.
ms_btime2isotimestr generates an ISO recommended format time string from a btime. Example:
'2001-07-29T12:38:00.0000'. The isotimestr must have enough room for 25 characters. The resulting
string will be NULL terminated.
ms_btime2mdtimestr generates a month-day formatted time string from a btime. Example: '2001-07-29
12:38:00.0000'. The mdtimestr must have enough room for 25 characters. The resulting string will be
NULL terminated.
ms_btime2seedtimestr generates a SEED format time string from a btime. Example:
'2001,195,12:38:00.0000'. The seedtimestr must have enough room for 23 characters. The resulting string
will be NULL terminated.
ms_hptime2btime converts a hptime to a btime. By default, hptime has microsecond precision whereas a
BTime structure can only represent time to 0.0001 seconds. 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.
ms_hptime2isotimestr generates an ISO recommended format time string from a hptime. Example:
'2001-07-29T12:38:00.000000' or '2001-07-29T12:38:00'. The isotimestr must have enough room for 27
characters. The subseconds flag controls whether the sub-second precision is included or not. The
resulting string will be NULL terminated.
ms_hptime2mdtimestr generates a month-day formatted time string from a hptime. Example: '2001-07-29
12:38:00.000000' or '2001-07-29 12:38:00'. The isotimestr must have enough room for 27 characters. The
subseconds flag controls whether the sub-second precision is included or not. The resulting string will
be NULL terminated.
ms_hptime2seedtimestr generates a SEED format time string from a hptime. Example:
'2001,195,12:38:00.000000' or '2001,195,12:38:00'. The seedtimestr must have enough room for 25
characters. The subseconds flag controls whether the sub-second precision is included or not. The
resulting string will be NULL terminated.
ms_time2hptime converts the time represented by the specified year, day, hour, min, sec and usec
(microseconds) to an hptime. 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.