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


#1

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

#!/bin/bash
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
exit

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

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

How to fix this?


#2

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. https://stackoverflow.com/a/26312460

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: https://app.bitrise.io/build/2f8334a7246cdb4a

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

#3

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?