Last active
August 29, 2015 14:10
-
-
Save bzikarsky/c309a55fefbaf9bdaa5d to your computer and use it in GitHub Desktop.
Test timezone behavior with PHP and Mongo
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" | |
TZ="/usr/share/zoneinfo/Europe/$ZONE" php -r "(new MongoClient())->selectDB('$DB')->selectCollection('$COL')->insert(['tz' => date('e'), 'time' => new MongoDate(strtotime('$DA | |
TE'))]);" | |
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" | |
TZ="/usr/share/zoneinfo/Europe/$ZONE" php -r "\$c = (new MongoClient)->selectDB('$DB')->selectCollection('$COL')->find(); foreach (\$c as \$d) echo ' => ', \$d['tz'], ' ', d | |
ate('c', \$d['time']->sec), PHP_EOL;" | |
done |
Author
bzikarsky
commented
Nov 29, 2014
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment