Skip to content

Compute Unix time in 64 bits to avoid Y2038 problem

Karl Wette requested to merge ANU-CGA/lalsuite:unix-epoch-compute-64-bit into master

Description

When computing a Unix time (seconds since 1/1/1970) from a struct tm, the computation needs to happen in 64 bits to avoid the Y2038 problem. Since the fields of struct tm are int (32 bits) they need to be cast to time_t (64 bits) first.

This MR moves the private function XLALSecondsSinceUnixEpoch(), which computes Unix time from a struct tm, from lalframe/lib/LALFrameIO.c to lal/lib/date/XLALCivilTime.c, and adds the correct casts for the struct tm fields to time_t. XLALSecondsSinceUnixEpoch() is then used in the 2 other locations the Unix time computation is needed: XLALUTCToGPS() in lal/lib/date/XLALCivilTime.c, and gps_to_unix() in lalapps/src/lalapps/tconvert.c.

Fixes the GPS to date bug in lalapps_tconvert reported in #186 (closed)

API Changes and Justification

Backwards Compatible Changes

  • This change does not modify any class/function/struct/type definitions in a public C header file or any Python class/function definitions
  • This change adds new classes/functions/structs/types to a public C header file or Python module

Backwards Incompatible Changes

  • This change modifies an existing class/function/struct/type definition in a public C header file or Python module
  • This change removes an existing class/function/struct/type from a public C header file or Python module

Review Status

cc @jolien-creighton @adam-mercer @david-keitel

Merge request reports