Skip to content

Use -u instead of --utc for date command

Timo Furrer requested to merge darwin-date-cmd into master
  • Use -u instead of --utc for date command

The --utc option seems to be non standard on some systems, e.g. darwin.

Changelog: fixed

Test Protocol

  • date from darwin ... (BSD?!)
❯ /bin/date -v
/bin/date: option requires an argument -- v
usage: date [-jnRu] [-I[date|hours|minutes|seconds]] [-f input_fmt]
            [-r filename|seconds] [-v[+|-]val[y|m|w|d|H|M|S]]
            [[[[mm]dd]HH]MM[[cc]yy][.SS] | new_date] [+output_fmt]

~/work/gitlab/gitlab-agent darwin-date-cmd*
❯ /bin/date --help
/bin/date: illegal option -- -
usage: date [-jnRu] [-I[date|hours|minutes|seconds]] [-f input_fmt]
            [-r filename|seconds] [-v[+|-]val[y|m|w|d|H|M|S]]
            [[[[mm]dd]HH]MM[[cc]yy][.SS] | new_date] [+output_fmt]

~/work/gitlab/gitlab-agent darwin-date-cmd*
❯ /bin/date -u -Iseconds
2024-04-30T05:31:05+00:00
  • busybox date from alpine:
~/work/gitlab/gitlab-agent darwin-date-cmd*
❯ alpine
Running /bin/sh in alpine:latest (cwd is at /app):
/ # date --help
BusyBox v1.36.1 (2023-11-07 18:53:09 UTC) multi-call binary.

Usage: date [OPTIONS] [+FMT] [[-s] TIME]

Display time (using +FMT), or set time

        -u              Work in UTC (don't convert to local time)
        [-s] TIME       Set time to TIME
        -d TIME         Display TIME, not 'now'
        -D FMT          FMT (strptime format) for -s/-d TIME conversion
        -r FILE         Display last modification time of FILE
        -R              Output RFC-2822 date
        -I[SPEC]        Output ISO-8601 date
                        SPEC=date (default), hours, minutes, seconds or ns

Recognized TIME formats:
        @seconds_since_1970
        hh:mm[:ss]
        [YYYY.]MM.DD-hh:mm[:ss]
        YYYY-MM-DD hh:mm[:ss]
        [[[[[YY]YY]MM]DD]hh]mm[.ss]
        'date TIME' form accepts MMDDhhmm[[YY]YY][.ss] instead
/ # date -u -Iseconds
2024-04-30T05:31:15+00:00
  • GNU date (coreutils):
~/work/gitlab/gitlab-agent darwin-date-cmd* 9s
❯ date --version
date (GNU coreutils) 9.5
Copyright (C) 2024 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Written by David MacKenzie.

~/work/gitlab/gitlab-agent darwin-date-cmd*
❯ date -u -Iseconds
2024-04-30T05:31:30+00:00
Edited by Timo Furrer

Merge request reports