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.

#!/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?

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’

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?

Hi @toshi0383,

You can set timezone with systemsetup -settimezone <tz>. For a list of valid <tz> values, see systemsetup -listtimezones.

However, I’m not sure if setting the system timezone would help. If I understand your setup correctly, PlistBuddy reads these date strings from files you provide and gdate fails to process specific strings, because the date encoded in the string does not exist in the given timezone in the string itself.

Thus, whatever you set your timezone, the same issue would occur.

I recommend converting the date strings to use numeric timezone corrections instead (see: http://www.gnu.org/software/coreutils/manual/html_node/Time-zone-items.html#Time-zone-items) or even better, if you have control over the writing of the input files, you could transform the strings before they get saved.

Let me know if this helps. :slight_smile:

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.