Skip to content

Instantly share code, notes, and snippets.

@bzikarsky
Created November 30, 2014 09:12
Show Gist options
  • Save bzikarsky/4044d1fa37e32e5c6996 to your computer and use it in GitHub Desktop.
Save bzikarsky/4044d1fa37e32e5c6996 to your computer and use it in GitHub Desktop.
#!/bin/bash
DB="test"
COL="tz"
ZONES="London Berlin Istanbul"
DATE="2000-01-01"
echo "System timezone: $(date -R)"
echo ""
echo -ne "Drop collection $COL: "
echo "db.${COL}.drop()" | mongo $DB --quiet
echo ""
echo "Inserting $DATE in different timezones"
for ZONE in $ZONES
do
echo "- Europe/$ZONE"
php -r "date_default_timezone_set('Europe/$ZONE'); (new MongoClient())->selectDB('$DB')->selectCollection('$COL')->insert(['tz' => date('e'), 'time' => new MongoDate(strtotim
e('$DATE'))]);"
done
echo ""
echo "DB contents"
echo "db.${COL}.find()" | mongo $DB --quiet
echo ""
echo "Reading in different timezones"
for ZONE in $ZONES
do
echo "- Europe/$ZONE"
php -r "date_default_timezone_set('Europe/$ZONE'); \$c = (new MongoClient)->selectDB('$DB')->selectCollection('$COL')->find(); foreach (\$c as \$d) echo ' => ', \$d['tz'],
' ', date('c', \$d['time']->sec), PHP_EOL;"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment