From: Tim Wood Date: Thu, 3 May 2012 19:46:10 +0000 (-0700) Subject: Adding zone tests #298 X-Git-Tag: 1.7.0~43^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=62c6d92fdad2a85f3ff281d6a89b937c54e4d72e;p=thirdparty%2Fmoment.git Adding zone tests #298 --- diff --git a/Makefile b/Makefile index b5d9cfa5e..5327ef4a2 100644 --- a/Makefile +++ b/Makefile @@ -51,6 +51,8 @@ size-history: moment .PHONY: test hint test-moment test-lang test: hint test-moment test-lang +test-zone: + sh ./test/zone.sh hint: node_modules/.bin/jshint moment.js diff --git a/test/moment/add_subtract.js b/test/moment/add_subtract.js index 5a9fffbed..1241befc7 100644 --- a/test/moment/add_subtract.js +++ b/test/moment/add_subtract.js @@ -117,6 +117,8 @@ exports.add_subtract = { test.equal(a.hours(), 5, 'adding days over DST difference should result in the same hour'); if (b.isDST() && !d.isDST()) { test.equal(b.hours(), 6, 'adding hours over DST difference should result in a different hour'); + } else if (!b.isDST() && d.isDST()) { + test.equal(b.hours(), 4, 'adding hours over DST difference should result in a different hour'); } else { test.equal(b.hours(), 5, 'adding hours over DST difference should result in a same hour if the timezone does not have daylight savings time'); } diff --git a/test/moment/utc.js b/test/moment/utc.js index 866bd5472..a58a21fab 100644 --- a/test/moment/utc.js +++ b/test/moment/utc.js @@ -20,7 +20,7 @@ exports.utc = { test.equal(m.date(), 2, "the date should be correct for local"); test.equal(m.day(), 3, "the day should be correct for local"); } - var zone = (m.zone() > 0) ? Math.floor(m.zone() / 60) : Math.ceil(m.zone() / 60); + var zone = (m.zone() > 0) ? Math.ceil(m.zone() / 60) : Math.floor(m.zone() / 60); var expected = (24 + 3 - zone) % 24; test.equal(m.hours(), expected, "the hours (" + m.hours() + ") should be correct for local"); test.equal(moment().utc().zone(), 0, "timezone in utc should always be zero"); diff --git a/test/zone.sh b/test/zone.sh new file mode 100644 index 000000000..0c69ec073 --- /dev/null +++ b/test/zone.sh @@ -0,0 +1,14 @@ +ZONE=$(systemsetup -gettimezone | sed "s/Time Zone: //g") + +names=(Pacific/Pago_Pago Pacific/Honolulu America/Adak Pacific/Apia Pacific/Marquesas Pacific/Gambier America/Anchorage Pacific/Pitcairn America/Los_Angeles America/Santa_Isabel America/Phoenix America/Denver America/Mazatlan America/Guatemala America/Chicago America/Mexico_City America/Bogota Pacific/Easter America/Havana America/New_York America/Caracas America/Santo_Domingo America/Goose_Bay America/Halifax America/St_Johns America/Argentina/Buenos_Aires America/Campo_Grande America/Santiago America/Miquelon America/Godthab America/Asuncion Atlantic/Stanley America/Noronha America/Sao_Paulo America/Montevideo Atlantic/Cape_Verde Atlantic/Azores Africa/Casablanca Europe/London Africa/Lagos Europe/Berlin Asia/Gaza Asia/Beirut Europe/Minsk Europe/Istanbul Asia/Damascus Asia/Jerusalem Africa/Windhoek Africa/Cairo Africa/Johannesburg Asia/Baghdad Europe/Moscow Asia/Tehran Asia/Dubai Asia/Yerevan Asia/Baku Asia/Kabul Asia/Karachi Asia/Yekaterinburg Asia/Kolkata Asia/Kathmandu Asia/Dhaka Asia/Omsk Asia/Rangoon Asia/Jakarta Asia/Krasnoyarsk Asia/Shanghai Asia/Irkutsk Australia/Eucla Asia/Tokyo Asia/Yakutsk Australia/Darwin Australia/Brisbane Asia/Vladivostok Australia/Adelaide Pacific/Noumea Asia/Kamchatka Australia/Lord_Howe Australia/Sydney Pacific/Norfolk Pacific/Tarawa Pacific/Tongatapu Pacific/Fiji Pacific/Auckland Pacific/Chatham Pacific/Kiritimati) + +for name in ${names[@]} +do + echo "\n\n\n\n\n\n--- Start tests for $name ---" + systemsetup settimezone $name + node_modules/.bin/nodeunit ./test/moment ./test/lang --reporter minimal + echo "--- End tests ---" +done + +echo "\n\n--- All tests done! Resetting timezone to $ZONE ---" +systemsetup settimezone $ZONE \ No newline at end of file