From 308e4ce800053d5fc50c18aae0392352cb305693 Mon Sep 17 00:00:00 2001 From: michaelahlers Date: Wed, 24 Apr 2013 15:39:20 -0400 Subject: [PATCH 01/27] For WebStorm users. --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index 8d4ae25..8c31602 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ +.idea bower_components +node_modules \ No newline at end of file From 45d4ba6d1371b336d0e5265fe5e09df2082c08d6 Mon Sep 17 00:00:00 2001 From: michaelahlers Date: Wed, 24 Apr 2013 15:39:38 -0400 Subject: [PATCH 02/27] Initial descriptor for NPM (used primarily to start tests). --- package.json | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 package.json diff --git a/package.json b/package.json new file mode 100644 index 0000000..4f058d3 --- /dev/null +++ b/package.json @@ -0,0 +1,33 @@ +{ + "name" : "angular-timezone-js", + "description" : "TimezoneJS for AngularJS", + "version" : "0.1.0", + "homepage" : "https://github.com/LeZuse/angular-timezone-js", + "author" : "Tomas Ruzicka ", + + "repository" : { + "type" : "git", + "url" : "git@github.com:LeZuse/angular-timezone-js.git" + }, + + "engines" : { + "node" : ">= 0.8" + }, + + "dependencies" : {}, + + "devDependencies" : { + "karma" : "0.8.x" + }, + + "scripts" : { + "test" : "karma start test/karma.conf.js --single-run --browsers PhantomJS" + }, + + "contributors" : [ + { + "name" : "Michael Ahlers", + "email" : "michael@ahlers.co" + } + ] +} \ No newline at end of file From 6c45b424baf7755f0f6a8ad15a808b43e1336dd2 Mon Sep 17 00:00:00 2001 From: michaelahlers Date: Wed, 24 Apr 2013 15:39:50 -0400 Subject: [PATCH 03/27] Test configuration. --- test/karma.conf.js | 70 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 test/karma.conf.js diff --git a/test/karma.conf.js b/test/karma.conf.js new file mode 100644 index 0000000..49af705 --- /dev/null +++ b/test/karma.conf.js @@ -0,0 +1,70 @@ +/** + * Testacular configuration. Visit https://github.com/vojtajina/testacular/blob/stable/lib/config.js#L54 + * for all available config options and defaults. + */ + +/* Base path, that will be used to resolve files and exclude. */ +basePath = './..'; + +/* Frameworks. */ +// frameworks = ['jasmine']; + +/* Files and patterns to load in the browser. */ +files = [ + JASMINE, + JASMINE_ADAPTER, + 'http://code.jquery.com/jquery-1.9.1.js', + 'http://code.angularjs.org/1.1.4/angular.js', + 'http://code.angularjs.org/1.1.4/angular-mocks.js', + 'https://raw.github.com/mde/timezone-js/master/src/date.js', + 'js/timezone.js', + 'test/directives/*Spec.js' +]; + +/* Files to exclude. */ +exclude = []; + +/* CLI progress reporters. Use dots, Travis terminal does not support escaping + * sequences. Legal values: 'dots', 'progress', 'junit'. */ +reporters = ['progress']; + +/* web server port */ +// --port 9876 +port = 9876; + +/* CLI runner port. */ +// --runner-port 9100 +runnerPort = 9100; + +/* Enable colors in the output (reporters and logs). */ +// --colors +// --no-colors +colors = true; + +/* Logging level. Possible values: LOG_DISABLE, LOG_ERROR, LOG_WARN, LOG_INFO, + * LOG_DEBUG. */ +// --log-level debug +logLevel = LOG_INFO; + +/* Enable watching file and executing tests whenever any file changes. */ +// --auto-watch +// --no-auto-watch +autoWatch = true; + +/* Testing environment. Options are (as available) Chrome, ChromeCanary, + * Firefox, Opera, Safari, PhantomJS, and IE. */ +// --browsers Chrome,Firefox,Safari +browsers = ['PhantomJS']; + +/* Timeout (in milliseconds) for browser capture. */ +// --capture-timeout 5000 +captureTimeout = 5000; + +/* Run tests on start (when browsers are captured) and exit. */ +// --single-run +// --no-single-run +singleRun = false; + +/* Report which specs are take longer than 500 ms to complete. */ +// --report-slower-than 500 +reportSlowerThan = 500; From 145008b1ef72bae4166541c3c82c857a747b04bf Mon Sep 17 00:00:00 2001 From: michaelahlers Date: Wed, 24 Apr 2013 15:40:07 -0400 Subject: [PATCH 04/27] I hate semis. --- test/karma.conf.js | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/test/karma.conf.js b/test/karma.conf.js index 49af705..9683012 100644 --- a/test/karma.conf.js +++ b/test/karma.conf.js @@ -4,10 +4,10 @@ */ /* Base path, that will be used to resolve files and exclude. */ -basePath = './..'; +basePath = './..' /* Frameworks. */ -// frameworks = ['jasmine']; +// frameworks = ['jasmine'] /* Files and patterns to load in the browser. */ files = [ @@ -19,52 +19,52 @@ files = [ 'https://raw.github.com/mde/timezone-js/master/src/date.js', 'js/timezone.js', 'test/directives/*Spec.js' -]; +] /* Files to exclude. */ -exclude = []; +exclude = [] /* CLI progress reporters. Use dots, Travis terminal does not support escaping * sequences. Legal values: 'dots', 'progress', 'junit'. */ -reporters = ['progress']; +reporters = ['progress'] /* web server port */ // --port 9876 -port = 9876; +port = 9876 /* CLI runner port. */ // --runner-port 9100 -runnerPort = 9100; +runnerPort = 9100 /* Enable colors in the output (reporters and logs). */ // --colors // --no-colors -colors = true; +colors = true /* Logging level. Possible values: LOG_DISABLE, LOG_ERROR, LOG_WARN, LOG_INFO, * LOG_DEBUG. */ // --log-level debug -logLevel = LOG_INFO; +logLevel = LOG_INFO /* Enable watching file and executing tests whenever any file changes. */ // --auto-watch // --no-auto-watch -autoWatch = true; +autoWatch = true /* Testing environment. Options are (as available) Chrome, ChromeCanary, * Firefox, Opera, Safari, PhantomJS, and IE. */ // --browsers Chrome,Firefox,Safari -browsers = ['PhantomJS']; +browsers = ['PhantomJS'] /* Timeout (in milliseconds) for browser capture. */ // --capture-timeout 5000 -captureTimeout = 5000; +captureTimeout = 5000 /* Run tests on start (when browsers are captured) and exit. */ // --single-run // --no-single-run -singleRun = false; +singleRun = false /* Report which specs are take longer than 500 ms to complete. */ // --report-slower-than 500 -reportSlowerThan = 500; +reportSlowerThan = 500 From c9aa8c1e9923a6e87d6f5e72fa0b1fb79a11d91c Mon Sep 17 00:00:00 2001 From: Michael Ahlers Date: Wed, 24 Apr 2013 16:51:00 -0300 Subject: [PATCH 05/27] Notes on running tests. --- README.md | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index e71f10d..b245f53 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,19 @@ -TimezoneJS for AngularJS -======================== +# TimezoneJS for AngularJS You need: -- npm -- bower +- NPM +- Bower -TODO ----- +## To Do -- Angular Date detection prevents using date filter for TimezoneJS instances – now using patched version of Angular +- Angular Date detection prevents using date filter for [TimezoneJS](https://github.com/mde/timezone-js/) instances—now using patched version of Angular. + +## Developers + +_TimezoneJS for Angular_ is tested with [Karma](http://karma-runner.github.io/) and [PhantomJS](http://phantomjs.org/) against the latest available release of [jQuery](http://jquery.com/) (1.9.1) and [AngularJS](http://angularjs.com/) (1.1.4). + +``` +$ npm install --dev +$ npm test +``` From b2d9f6abe885bb648523886555c8095db0dd1be5 Mon Sep 17 00:00:00 2001 From: michaelahlers Date: Wed, 24 Apr 2013 15:53:47 -0400 Subject: [PATCH 06/27] Travis CI configuration. --- .travis.yml | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..5c60f47 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,14 @@ +language: node_js + +node_js: + - "0.8" + - "0.10" + +before_script: + - export DISPLAY=:99.0 + - export PHANTOMJS_BIN=/usr/local/phantomjs/bin/phantomjs + - sh -e /etc/init.d/xvfb start + - sleep 3 # give xvfb some time to start + +script: + - npm test From d05c785a8e87ef3a6f080d833a1fde71ac220de5 Mon Sep 17 00:00:00 2001 From: michaelahlers Date: Wed, 24 Apr 2013 16:13:00 -0400 Subject: [PATCH 07/27] Include PhantomJS as a devDependency. --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 4f058d3..8c2b24e 100644 --- a/package.json +++ b/package.json @@ -17,11 +17,12 @@ "dependencies" : {}, "devDependencies" : { - "karma" : "0.8.x" + "karma" : "0.8.x", + "phantomjs" : "1.9.x" }, "scripts" : { - "test" : "karma start test/karma.conf.js --single-run --browsers PhantomJS" + "test" : "karma start test/karma.conf.js" }, "contributors" : [ From a66f941799f35dc1c22e77aa82f33bd8a93875de Mon Sep 17 00:00:00 2001 From: michaelahlers Date: Wed, 24 Apr 2013 16:16:50 -0400 Subject: [PATCH 08/27] Single run by default. --- test/karma.conf.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/karma.conf.js b/test/karma.conf.js index 9683012..0937eb2 100644 --- a/test/karma.conf.js +++ b/test/karma.conf.js @@ -63,7 +63,7 @@ captureTimeout = 5000 /* Run tests on start (when browsers are captured) and exit. */ // --single-run // --no-single-run -singleRun = false +singleRun = true /* Report which specs are take longer than 500 ms to complete. */ // --report-slower-than 500 From 438346928b9b94685592967ea8f1549dda3d96c8 Mon Sep 17 00:00:00 2001 From: michaelahlers Date: Wed, 24 Apr 2013 16:17:10 -0400 Subject: [PATCH 09/27] First cut. --- test/directives/tzDateSpec.js | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 test/directives/tzDateSpec.js diff --git a/test/directives/tzDateSpec.js b/test/directives/tzDateSpec.js new file mode 100644 index 0000000..32ac665 --- /dev/null +++ b/test/directives/tzDateSpec.js @@ -0,0 +1,25 @@ +'use strict' + +describe('tzDate', function () { + var scope, $sandbox, $compile, $timeout + + beforeEach(module('timezonejs')) + + beforeEach(inject(function ($injector, $rootScope, _$compile_, _$timeout_) { + scope = $rootScope + $compile = _$compile_ + $timeout = _$timeout_ + + $sandbox = $('
').appendTo($('body')) + })) + + afterEach(function () { + $sandbox.remove() + scope.$destroy() + }) + + it('should work', function () { + expect(true).toBe(true) + }) + +}) \ No newline at end of file From 411b29fcf8b6e7825c2c8ea33813cbaf1e9db293 Mon Sep 17 00:00:00 2001 From: michaelahlers Date: Wed, 24 Apr 2013 16:20:18 -0400 Subject: [PATCH 10/27] Link to Travis. --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index b245f53..8fe6aaa 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ -# TimezoneJS for AngularJS +# TimezoneJS for AngularJS [![Build Status](https://secure.travis-ci.org/michaelahlers/angular-timezone-js.png)](http://travis-ci.org/michaelahlers/angular-timezone-js) You need: - + - NPM - Bower From 580d3abaecc536e27e2eed7950199f85c9f492a1 Mon Sep 17 00:00:00 2001 From: michaelahlers Date: Wed, 24 Apr 2013 16:21:07 -0400 Subject: [PATCH 11/27] We're not concerned with multiple Node releases. --- .travis.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 5c60f47..ed51552 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,6 @@ language: node_js node_js: - - "0.8" - "0.10" before_script: From 1918dfee2ad408610287edfab380f06d1b2bb3d6 Mon Sep 17 00:00:00 2001 From: michaelahlers Date: Wed, 24 Apr 2013 16:28:47 -0400 Subject: [PATCH 12/27] Not necessary per http://about.travis-ci.org/docs/user/gui-and-headless-browsers/#Using-PhantomJS. --- .travis.yml | 6 ------ 1 file changed, 6 deletions(-) diff --git a/.travis.yml b/.travis.yml index ed51552..7ce6dda 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,11 +3,5 @@ language: node_js node_js: - "0.10" -before_script: - - export DISPLAY=:99.0 - - export PHANTOMJS_BIN=/usr/local/phantomjs/bin/phantomjs - - sh -e /etc/init.d/xvfb start - - sleep 3 # give xvfb some time to start - script: - npm test From 3608487cf4bb9edccc4e3cf3fae419360dc308d1 Mon Sep 17 00:00:00 2001 From: michaelahlers Date: Wed, 24 Apr 2013 17:01:50 -0400 Subject: [PATCH 13/27] A valid test, but failing. --- test/directives/tzDateSpec.js | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/test/directives/tzDateSpec.js b/test/directives/tzDateSpec.js index 32ac665..f1b34db 100644 --- a/test/directives/tzDateSpec.js +++ b/test/directives/tzDateSpec.js @@ -13,13 +13,36 @@ describe('tzDate', function () { $sandbox = $('
').appendTo($('body')) })) + var compile = function (scenario) { + scenario = scenarios[scenario] + angular.extend(scope, scenario.scope) + + var $element = $(scenario.element).appendTo($sandbox) + + $element = $compile($element)(scope) + scope.$digest() + + return $element + } + afterEach(function () { $sandbox.remove() scope.$destroy() }) - it('should work', function () { - expect(true).toBe(true) + var scenarios = { + 'America/Chicago' : { + scope : { + reference : new Date(Date.parse('1970-01-01T00:00:00+00:00')), + timezone : 'America/Chicago' + }, + element : '{{reference|tzDate:timezone|date:"yyyy-MM-dd HH:mm:ss Z"}}' + } + } + + it('should format reference date to America/Chicago', function () { + var el = compile('America/Chicago') + expect(el.text()).toEqual('1969-12-31 18:00:00 -0600') }) }) \ No newline at end of file From 542d2b85698307a53ce02e1d50d2c278db697efb Mon Sep 17 00:00:00 2001 From: michaelahlers Date: Wed, 24 Apr 2013 17:10:31 -0400 Subject: [PATCH 14/27] TimezoneJS is required. --- js/bower.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/js/bower.json b/js/bower.json index e1747cc..d389fa7 100644 --- a/js/bower.json +++ b/js/bower.json @@ -4,6 +4,7 @@ "dependencies": { "angular": "latest", "jquery": "latest", - "angular-filters": "latest" + "angular-filters": "latest", + "timezone-js": "git@github.com:mde/timezone-js.git" } } \ No newline at end of file From 592b75db2f36322d388964f183b3a690d5866fcf Mon Sep 17 00:00:00 2001 From: michaelahlers Date: Wed, 24 Apr 2013 17:46:00 -0400 Subject: [PATCH 15/27] Inject $filter for future test cases. --- test/directives/tzDateSpec.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/test/directives/tzDateSpec.js b/test/directives/tzDateSpec.js index f1b34db..5d72a11 100644 --- a/test/directives/tzDateSpec.js +++ b/test/directives/tzDateSpec.js @@ -1,12 +1,13 @@ 'use strict' describe('tzDate', function () { - var scope, $sandbox, $compile, $timeout + var scope, $filter, $compile, $timeout, $sandbox beforeEach(module('timezonejs')) - beforeEach(inject(function ($injector, $rootScope, _$compile_, _$timeout_) { + beforeEach(inject(function ($injector, $rootScope, _$filter_, _$compile_, _$timeout_) { scope = $rootScope + $filter = _$filter_ $compile = _$compile_ $timeout = _$timeout_ @@ -34,13 +35,13 @@ describe('tzDate', function () { 'America/Chicago' : { scope : { reference : new Date(Date.parse('1970-01-01T00:00:00+00:00')), - timezone : 'America/Chicago' + timezone : 'America/New_York' }, element : '{{reference|tzDate:timezone|date:"yyyy-MM-dd HH:mm:ss Z"}}' } } - it('should format reference date to America/Chicago', function () { + it('should support date formatting for America/Chicago', function () { var el = compile('America/Chicago') expect(el.text()).toEqual('1969-12-31 18:00:00 -0600') }) From ac24600862dfc2e40975fbb68e4c599ffd9b74ad Mon Sep 17 00:00:00 2001 From: michaelahlers Date: Thu, 25 Apr 2013 12:39:18 -0400 Subject: [PATCH 16/27] Tweaks. Serve the timezones. --- test/karma.conf.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/test/karma.conf.js b/test/karma.conf.js index 0937eb2..6143c5b 100644 --- a/test/karma.conf.js +++ b/test/karma.conf.js @@ -6,18 +6,19 @@ /* Base path, that will be used to resolve files and exclude. */ basePath = './..' -/* Frameworks. */ -// frameworks = ['jasmine'] - /* Files and patterns to load in the browser. */ files = [ JASMINE, JASMINE_ADAPTER, + 'http://code.jquery.com/jquery-1.9.1.js', 'http://code.angularjs.org/1.1.4/angular.js', 'http://code.angularjs.org/1.1.4/angular-mocks.js', 'https://raw.github.com/mde/timezone-js/master/src/date.js', + + { pattern : 'js/lib/timezones.json', included : false }, 'js/timezone.js', + 'test/directives/*Spec.js' ] From 6d9f4c324497325814b2d0e1759f207077970e1f Mon Sep 17 00:00:00 2001 From: michaelahlers Date: Thu, 25 Apr 2013 12:50:18 -0400 Subject: [PATCH 17/27] Use provided constant if available. --- js/timezone.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/js/timezone.js b/js/timezone.js index 444bb83..c94cdb0 100644 --- a/js/timezone.js +++ b/js/timezone.js @@ -1,10 +1,10 @@ var timezonejs = angular.module('timezonejs', []); -timezonejs.factory('Timezone', function() { +timezonejs.factory('Timezone', function(timezonesURL) { var _tz = timezoneJS.timezone; _tz.loadingScheme = _tz.loadingSchemes.MANUAL_LOAD; // TODO: load with ang? - _tz.loadZoneJSONData('js/lib/timezones.json', true); + _tz.loadZoneJSONData(timezonesURL || 'js/lib/timezones.json', true); timezoneJS.fromLocalString = function(str, tz) { // https://github.com/csnover/js-iso8601/blob/master/iso8601.js – MIT license From 5b8f3fd2ccf79310c59051e609a2b8d9c52675fc Mon Sep 17 00:00:00 2001 From: michaelahlers Date: Thu, 25 Apr 2013 12:55:30 -0400 Subject: [PATCH 18/27] Make this truly optional. --- js/timezone.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/js/timezone.js b/js/timezone.js index c94cdb0..7a31dd9 100644 --- a/js/timezone.js +++ b/js/timezone.js @@ -1,10 +1,16 @@ var timezonejs = angular.module('timezonejs', []); -timezonejs.factory('Timezone', function(timezonesURL) { +timezonejs.factory('Timezone', function($injector) { var _tz = timezoneJS.timezone; _tz.loadingScheme = _tz.loadingSchemes.MANUAL_LOAD; // TODO: load with ang? - _tz.loadZoneJSONData(timezonesURL || 'js/lib/timezones.json', true); + + try { + _tz.loadZoneJSONData($injector.get('timezonesURL'), true); + } catch (e) { + _tz.loadZoneJSONData('js/lib/timezones.json', true); + } + timezoneJS.fromLocalString = function(str, tz) { // https://github.com/csnover/js-iso8601/blob/master/iso8601.js – MIT license From 91197850b54be784844995ddb41638b7d85f5c49 Mon Sep 17 00:00:00 2001 From: michaelahlers Date: Thu, 25 Apr 2013 14:02:59 -0400 Subject: [PATCH 19/27] Real test. --- test/directives/tzDateSpec.js | 45 +++++++++++++++++++++++++++-------- 1 file changed, 35 insertions(+), 10 deletions(-) diff --git a/test/directives/tzDateSpec.js b/test/directives/tzDateSpec.js index 5d72a11..8b59e3d 100644 --- a/test/directives/tzDateSpec.js +++ b/test/directives/tzDateSpec.js @@ -3,7 +3,9 @@ describe('tzDate', function () { var scope, $filter, $compile, $timeout, $sandbox - beforeEach(module('timezonejs')) + beforeEach(module('timezonejs', function ($provide) { + $provide.value('timezonesURL', 'base/js/lib/timezones.json') + })) beforeEach(inject(function ($injector, $rootScope, _$filter_, _$compile_, _$timeout_) { scope = $rootScope @@ -18,7 +20,7 @@ describe('tzDate', function () { scenario = scenarios[scenario] angular.extend(scope, scenario.scope) - var $element = $(scenario.element).appendTo($sandbox) + var $element = $(scenario.markup).appendTo($sandbox) $element = $compile($element)(scope) scope.$digest() @@ -31,19 +33,42 @@ describe('tzDate', function () { scope.$destroy() }) - var scenarios = { - 'America/Chicago' : { + var scenarios = [ + { scope : { reference : new Date(Date.parse('1970-01-01T00:00:00+00:00')), - timezone : 'America/New_York' + timezone : 'America/New_York', + expected : { + fullYear : 1969, + month : 11, + date : 31, + hours : 20 + } }, - element : '{{reference|tzDate:timezone|date:"yyyy-MM-dd HH:mm:ss Z"}}' + markup : '{{reference|tzDate:timezone|date:"yyyy-MM-dd HH:mm:ss Z"}}' } - } + ] + + it('should align dates to expected timezones', function () { + scenarios.forEach(function (scenario) { + var timezone = scenario.scope.timezone + , reference = scenario.scope.reference + , expected = scenario.scope.expected - it('should support date formatting for America/Chicago', function () { - var el = compile('America/Chicago') - expect(el.text()).toEqual('1969-12-31 18:00:00 -0600') + var aligned = $filter('tzDate')(reference, timezone) + + expect(aligned.getTimezone()).toEqual(timezone) + + expect(aligned.getFullYear()).toEqual(expected.fullYear) + expect(aligned.getMonth()).toEqual(expected.month) + expect(aligned.getDate()).toEqual(expected.date) + expect(aligned.getHours()).toEqual(expected.hours) + }) }) +// it('should support date formatting for America/New_York', function () { +// var el = compile('America/New_York') +// expect(el.html()).toEqual('1969-12-31 19:00:00 -0500') +// }) + }) \ No newline at end of file From ee6ac819d5687826b0c1b284601c6ab1524d25e9 Mon Sep 17 00:00:00 2001 From: michaelahlers Date: Thu, 25 Apr 2013 14:03:47 -0400 Subject: [PATCH 20/27] Use another zone. --- test/directives/tzDateSpec.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/test/directives/tzDateSpec.js b/test/directives/tzDateSpec.js index 8b59e3d..bd12607 100644 --- a/test/directives/tzDateSpec.js +++ b/test/directives/tzDateSpec.js @@ -46,6 +46,19 @@ describe('tzDate', function () { } }, markup : '{{reference|tzDate:timezone|date:"yyyy-MM-dd HH:mm:ss Z"}}' + }, + { + scope : { + reference : new Date(Date.parse('1970-01-01T00:00:00+00:00')), + timezone : 'America/Los_Angeles', + expected : { + fullYear : 1969, + month : 11, + date : 31, + hours : 17 + } + }, + markup : '{{reference|tzDate:timezone|date:"yyyy-MM-dd HH:mm:ss Z"}}' } ] From 58aea76e58186c94e5b2fec6b9e25df6626c04fe Mon Sep 17 00:00:00 2001 From: michaelahlers Date: Thu, 25 Apr 2013 14:13:22 -0400 Subject: [PATCH 21/27] Test for formatted dates. --- test/directives/tzDateSpec.js | 47 +++++++++++++++++++---------------- 1 file changed, 26 insertions(+), 21 deletions(-) diff --git a/test/directives/tzDateSpec.js b/test/directives/tzDateSpec.js index bd12607..698e563 100644 --- a/test/directives/tzDateSpec.js +++ b/test/directives/tzDateSpec.js @@ -17,7 +17,6 @@ describe('tzDate', function () { })) var compile = function (scenario) { - scenario = scenarios[scenario] angular.extend(scope, scenario.scope) var $element = $(scenario.markup).appendTo($sandbox) @@ -37,28 +36,30 @@ describe('tzDate', function () { { scope : { reference : new Date(Date.parse('1970-01-01T00:00:00+00:00')), - timezone : 'America/New_York', - expected : { - fullYear : 1969, - month : 11, - date : 31, - hours : 20 - } + timezone : 'America/New_York' }, - markup : '{{reference|tzDate:timezone|date:"yyyy-MM-dd HH:mm:ss Z"}}' + markup : '{{reference|tzDate:timezone|date:"yyyy-MM-dd HH:mm:ss Z"}}', + expected : { + fullYear : 1969, + month : 11, + date : 31, + hours : 20, + text : '1969-12-31 20:00:00 -0400' + } }, { scope : { reference : new Date(Date.parse('1970-01-01T00:00:00+00:00')), - timezone : 'America/Los_Angeles', - expected : { - fullYear : 1969, - month : 11, - date : 31, - hours : 17 - } + timezone : 'America/Los_Angeles' }, - markup : '{{reference|tzDate:timezone|date:"yyyy-MM-dd HH:mm:ss Z"}}' + markup : '{{reference|tzDate:timezone|date:"yyyy-MM-dd HH:mm:ss Z"}}', + expected : { + fullYear : 1969, + month : 11, + date : 31, + hours : 17, + text : '1969-12-31 17:00:00 -0700' + } } ] @@ -66,7 +67,7 @@ describe('tzDate', function () { scenarios.forEach(function (scenario) { var timezone = scenario.scope.timezone , reference = scenario.scope.reference - , expected = scenario.scope.expected + , expected = scenario.expected var aligned = $filter('tzDate')(reference, timezone) @@ -79,9 +80,13 @@ describe('tzDate', function () { }) }) -// it('should support date formatting for America/New_York', function () { -// var el = compile('America/New_York') -// expect(el.html()).toEqual('1969-12-31 19:00:00 -0500') +// it('should support formatting dates to expected timezones', function () { +// scenarios.forEach(function (scenario) { +// var expected = scenario.expected +// , el = compile(scenario) +// +// expect(el.text()).toEqual(expected.text) +// }) // }) }) \ No newline at end of file From 13d1302ea33a84125c80f699f4ebd88e12e3c197 Mon Sep 17 00:00:00 2001 From: michaelahlers Date: Thu, 25 Apr 2013 14:13:44 -0400 Subject: [PATCH 22/27] For now, this test fails. The next step is to fix bugs. --- test/directives/tzDateSpec.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/test/directives/tzDateSpec.js b/test/directives/tzDateSpec.js index 698e563..085ee4e 100644 --- a/test/directives/tzDateSpec.js +++ b/test/directives/tzDateSpec.js @@ -80,13 +80,13 @@ describe('tzDate', function () { }) }) -// it('should support formatting dates to expected timezones', function () { -// scenarios.forEach(function (scenario) { -// var expected = scenario.expected -// , el = compile(scenario) -// -// expect(el.text()).toEqual(expected.text) -// }) -// }) + it('should support formatting dates to expected timezones', function () { + scenarios.forEach(function (scenario) { + var expected = scenario.expected + , el = compile(scenario) + + expect(el.text()).toEqual(expected.text) + }) + }) }) \ No newline at end of file From d4076be7e1e9ec68c66a4ff46ea4580a76f9196b Mon Sep 17 00:00:00 2001 From: michaelahlers Date: Thu, 25 Apr 2013 14:46:55 -0400 Subject: [PATCH 23/27] Add in hours and the TZ offset. --- index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.html b/index.html index 7aa0ff4..4cfb99a 100644 --- a/index.html +++ b/index.html @@ -12,6 +12,6 @@

Angular.js TimezoneJS demo

-

Hey folks! Today is {{ today | tzDate:timezone | date:"yyyy-MM-dd" }}

+

Hey folks! Today is {{ today | tzDate:timezone | date:"yyyy-MM-dd HH:mm:ss Z" }}

From d7fef5ac6a6f4b263510fddeac83a89570f61af1 Mon Sep 17 00:00:00 2001 From: michaelahlers Date: Thu, 25 Apr 2013 14:51:00 -0400 Subject: [PATCH 24/27] Wrap to prevent leaking variables to the global scope. --- js/timezone.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/js/timezone.js b/js/timezone.js index 7a31dd9..42f92ab 100644 --- a/js/timezone.js +++ b/js/timezone.js @@ -1,3 +1,5 @@ +(function(){ + var timezonejs = angular.module('timezonejs', []); timezonejs.factory('Timezone', function($injector) { @@ -37,3 +39,5 @@ timezonejs.filter('tzDate', function(Timezone) { return new Timezone.Date(dt, tz); }; }); + +})(angular) \ No newline at end of file From 8dd2a170bab159e015e327f9f93cf14b40950564 Mon Sep 17 00:00:00 2001 From: michaelahlers Date: Thu, 25 Apr 2013 14:51:49 -0400 Subject: [PATCH 25/27] Extend a native Date object to trick AngularJS's date filter into formatting it. --- js/timezone.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/js/timezone.js b/js/timezone.js index 42f92ab..d9c554b 100644 --- a/js/timezone.js +++ b/js/timezone.js @@ -1,5 +1,13 @@ (function(){ +var toExtendedNative = function (wrapped) { + var native = new Date() + for (key in wrapped) { + native[key] = wrapped[key] + } + return native +} + var timezonejs = angular.module('timezonejs', []); timezonejs.factory('Timezone', function($injector) { @@ -28,7 +36,7 @@ timezonejs.factory('Timezone', function($injector) { struct[2] = (+struct[2] || 1) - 1; struct[3] = +struct[3] || 1; - return new timezoneJS.Date(struct[1], struct[2], struct[3], struct[4], struct[5], struct[6], struct[7], tz); + return toExtendedNative(new timezoneJS.Date(struct[1], struct[2], struct[3], struct[4], struct[5], struct[6], struct[7], tz)); }; return timezoneJS; }); @@ -36,7 +44,7 @@ timezonejs.factory('Timezone', function($injector) { timezonejs.filter('tzDate', function(Timezone) { return function(dt, tz) { console.log('ar', arguments); - return new Timezone.Date(dt, tz); + return toExtendedNative(new Timezone.Date(dt, tz)); }; }); From 369f8b98e55b852a90270aed5d7e013c8296f365 Mon Sep 17 00:00:00 2001 From: michaelahlers Date: Thu, 25 Apr 2013 14:53:57 -0400 Subject: [PATCH 26/27] Note to self. --- js/timezone.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/js/timezone.js b/js/timezone.js index d9c554b..88ff4eb 100644 --- a/js/timezone.js +++ b/js/timezone.js @@ -1,6 +1,8 @@ (function(){ var toExtendedNative = function (wrapped) { + /* Tricks the isDate method in Angular into treating these objects like it + * would any other Date. May be horribly slow. */ var native = new Date() for (key in wrapped) { native[key] = wrapped[key] From b12464573fda02b6e24e66b1729862088460b032 Mon Sep 17 00:00:00 2001 From: michaelahlers Date: Thu, 25 Apr 2013 15:06:13 -0400 Subject: [PATCH 27/27] Angular now tricked into accepting our date objects. --- README.md | 4 ---- 1 file changed, 4 deletions(-) diff --git a/README.md b/README.md index 8fe6aaa..588d28d 100644 --- a/README.md +++ b/README.md @@ -5,10 +5,6 @@ You need: - NPM - Bower -## To Do - -- Angular Date detection prevents using date filter for [TimezoneJS](https://github.com/mde/timezone-js/) instances—now using patched version of Angular. - ## Developers _TimezoneJS for Angular_ is tested with [Karma](http://karma-runner.github.io/) and [PhantomJS](http://phantomjs.org/) against the latest available release of [jQuery](http://jquery.com/) (1.9.1) and [AngularJS](http://angularjs.com/) (1.1.4).