Gdate: invalid date ‘Mon Aug 05 19:49:04 PST 2019’


With Xcode10.1 stack, Bitrise has coreutils pre-installed.
I have a shell script to use gdate, but it fails sometimes.

echo 1
gdate -d "Sun Nov 24 16:32:10 PST 2019" +%s
echo 2
gdate -d "Mon Aug 05 19:49:04 PST 2019" +%s

It succeeds as expected on my local machine, but fails on Bitrise.

gdate: invalid date ‘Mon Aug 05 19:49:04 PST 2019’

How to fix this?


Hi @toshi0383,

Indeed this is really strange… It seems to be an issue in gdate, specific to High Sierra, at least I couldn’t reproduce it on Mojave, but it happens on every High Sierra config even with the latest coreutils available in brew :thinking:

A few notes/things I found:

  • It works if you replace the timezone PST with UTC
  • It also works with PDT instead of PST

I have no idea why it works on Mojave, but I found that daylight saving times can affect date see e.g.

If you check the date that fails, 2019 Aug 05, that’s not in PST (Pacific Standard Time) but in PDT (Pacific Daylight Time) timezone, that is in the summertime/daylight saving time. The other date is actually in PST, that’s why it doesn’t return an error, but Aug 05 2019 technically will be in PDT and not PST.

Again, why it does not return an error on Mojave, my best guess is there’s some difference in the High Sierra vs Mojave gdate versions that can be installed from brew.

One solution could be to use UTC as that does not have a daylight saving counterpart, for the one that has (e.g. PST <-> PDT) the High Sierra gdate expects the right one for the date.

Example build:

+ gdate -d 'Sun Nov 24 16:32:10 PST 2019' +%s
+ gdate -d 'Mon Aug 05 19:49:04 UTC 2019' +%s
+ gdate -d 'Mon Aug 05 19:49:04 PDT 2019' +%s
+ gdate -d 'Mon Aug 05 19:49:04 PST 2019' +%s
gdate: invalid date ‘Mon Aug 05 19:49:04 PST 2019’


Thanks for investigation.:innocent:

I found the one who produce “PST” date is PlistBuddy. I have this script to run on CI.

Do you have any idea to workaround this?
Maybe changing system timezone using systemsetup command?