Created
November 30, 2014 09:12
-
-
Save bzikarsky/4044d1fa37e32e5c6996 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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