├── .gitignore ├── .jshintrc ├── .travis.yml ├── Jakefile ├── README.md ├── benchmarks └── benchmark.js ├── bower.json ├── package.json ├── spec ├── date.spec.js ├── test-utils.js ├── tz.async.spec.js ├── tz.default.spec.js ├── tz.manual.spec.js ├── tz.preload.spec.js └── tz.sync.spec.js └── src ├── date.js ├── node-preparse.js ├── preparse.js └── strip_olson_comments.rb /.gitignore: -------------------------------------------------------------------------------- 1 | .DS* 2 | tests/tz 3 | tests/jasmine 4 | lib 5 | node_modules 6 | docs 7 | .c9* 8 | .settings 9 | *.local.spec.js 10 | -------------------------------------------------------------------------------- /.jshintrc: -------------------------------------------------------------------------------- 1 | { 2 | "laxcomma": true, 3 | "browser": true, 4 | "globalstrict": true, 5 | "strict": true, 6 | "expr": true, 7 | "multistr": true, 8 | "globals": { 9 | "define": true, 10 | "window": true, 11 | "module": true, 12 | "exports": true 13 | } 14 | } -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - "0.10" 4 | - "0.8" 5 | 6 | notifications: 7 | email: 8 | recipients: 9 | - mde@fleegix.org 10 | - holevietlong@gmail.com 11 | 12 | -------------------------------------------------------------------------------- /Jakefile: -------------------------------------------------------------------------------- 1 | var fs = require('fs') 2 | , path = require('path'); 3 | 4 | namespace('test', function () { 5 | 6 | desc('Sets up tests by downloading the timezone data.'); 7 | task('init', ['updateTzData'], function () { 8 | complete(); 9 | }, {async: true}); 10 | 11 | task('clobberTzData', function () { 12 | console.log('Removing old timezone data.'); 13 | jake.rmRf('lib/tz'); 14 | }); 15 | 16 | desc('Downloads the newest timezone data.'); 17 | task('updateTzData', ['clobberTzData'], function () { 18 | var cmds = [ 19 | 'echo "Downloading new timezone data ..."' 20 | , 'curl ftp://ftp.iana.org/tz/tzdata-latest.tar.gz ' + 21 | '-o lib/tz/tzdata-latest.tar.gz' 22 | , 'echo "Expanding archive ..."' 23 | , 'tar -xvzf lib/tz/tzdata-latest.tar.gz -C lib/tz' 24 | ]; 25 | jake.mkdirP('lib/tz'); 26 | jake.exec(cmds, function () { 27 | console.log('Retrieved new timezone data'); 28 | console.log('Parsing tz...'); 29 | jake.exec('node src/node-preparse.js lib/tz > lib/all_cities.json', function () { 30 | console.log('Done parsing tz'); 31 | complete(); 32 | }, {printStdout: true, printStderr: true}); 33 | }, {printStdout: true}); 34 | }, {async: true}); 35 | 36 | task('run', function () { 37 | //Comply to 0.8.0 and 0.6.x 38 | var existsSync = fs.existsSync || path.existsSync; 39 | if (!existsSync('lib/tz')) { 40 | fail('No timezone data. Please run "jake test:init".'); 41 | } 42 | jake.exec(['./node_modules/jasmine-node/bin/jasmine-node spec'], function () { 43 | complete(); 44 | }, {printStdout: true}); 45 | 46 | }, {async: true}); 47 | 48 | task('cli', ['init', 'run']); 49 | 50 | }); 51 | 52 | desc('Runs the tests.'); 53 | task('test', ['test:run'], function () {}); 54 | 55 | namespace('doc', function () { 56 | task('generate', ['doc:clobber'], function () { 57 | var cmd = 'docco src/date.js'; 58 | console.log('Generating docs ...'); 59 | jake.exec([cmd], function () { 60 | console.log('Done.'); 61 | complete(); 62 | }); 63 | }, {async: true}); 64 | 65 | task('clobber', function () { 66 | var cmd = 'rm -fr ./docs'; 67 | jake.exec([cmd], function () { 68 | console.log('Clobbered old docs.'); 69 | complete(); 70 | }); 71 | }, {async: true}); 72 | 73 | }); 74 | 75 | desc('Generates docs.'); 76 | task('doc', ['doc:generate']); 77 | 78 | publishTask('timezone-js', 79 | {versionFiles: ['package.json', 'bower.json']} , function () { 80 | this.packageFiles.include([ 81 | 'Jakefile' 82 | , 'README.md' 83 | , 'package.json' 84 | , 'spec/*' 85 | , 'src/*' 86 | ]); 87 | }); 88 | 89 | jake.Task['publish:updateVersionFiles'].on('complete', function (version) { 90 | var code = fs.readFileSync('./src/date.js').toString(); 91 | code = code.replace(/timezoneJS.VERSION = '.+'/m, 92 | "timezoneJS.VERSION = '" + version + "'"); 93 | fs.writeFileSync('./src/date.js', code); 94 | }); 95 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # TimezoneJS.Date 2 | 3 | [![Build Status](https://secure.travis-ci.org/mde/timezone-js.png)](https://secure.travis-ci.org/mde/timezone-js) 4 | 5 | A timezone-enabled, drop-in replacement for the stock JavaScript Date. The `timezoneJS.Date` object is API-compatible with JS Date, with the same getter and setter methods -- it should work fine in any code that works with normal JavaScript Dates. 6 | 7 | [Mailing list](http://groups.google.com/group/timezone-js) 8 | 9 | ## Overview 10 | 11 | The `timezoneJS.Date` object gives you full-blown timezone support, independent from the timezone set on the end-user's machine running the browser. It uses the Olson zoneinfo files for its timezone data. 12 | 13 | The constructor function and setter methods use proxy JavaScript Date objects behind the scenes, so you can use strings like '10/22/2006' with the constructor. You also get the same sensible wraparound behavior with numeric parameters (like setting a value of 14 for the month wraps around to the next March). 14 | 15 | The other significant difference from the built-in JavaScript Date is that `timezoneJS.Date` also has named properties that store the values of year, month, date, etc., so it can be directly serialized to JSON and used for data transfer. 16 | 17 | ## Setup 18 | 19 | This section shows the most common way of setting up timezone-js. In the 'Customizing' section below you can find alternative approaches. 20 | 21 | First you'll need to include the code on your page. Both `timezoneJS.Date`, and the supporting code it needs in `timezoneJS.timezone` are bundled in the `date.js` file in `src` directory. Include the code on your page with a normal JavaScript script include, like so: 22 | 23 |