Change 33190

tom_tyler (C. Thomas Tyler)
C. Thomas Tyler committed this change into //p4-sdp/dev_rebrand/Unsupported/Samples/bin
Request Review
Download .zip
Added sample epoch time conversion that works on many platforms.

Requirements:
* Works on Ubuntu 20-26, Rocky 8-10, SLES 15, and BSD and Mac (at least modern Mac, e.g. Tahoe)
* Accepts a datetamp in the form of YYYY/MM/DD or YYYY/MM/DD:HH:MM:SS (if the hour/minute/second is omitted, it defaults to 23:59:59).
* Provide an optional way to specify time zone, with UTC as the default.

Key Highlights
* Cross-Platform Compatibility: GNU Linux uses date -d, while BSD/macOS uses date -j -f "%Y/%m/%d %H:%M:%S". The if date --version check handles the branch automatically without relying on uname.
* Flexible Input: Handles both YYYY/MM/DD and YYYY/MM/DD:HH:MM:SS by leveraging shell parameter expansion (${INPUT_STAMP%%:*} and ${INPUT_STAMP#*:}).
* Timezone Safety: Sets TZ="$TARGET_TZ" per execution without mutating the caller's global shell environment.
  • Files 1
  • Comments 0
0 edited 1 added 0 deleted
to_epoch.sh#1
Loading...
Tip: Use n and p to cycle through the changes.