Skip to content

Commit

Permalink
Initial commit for the fork
Browse files Browse the repository at this point in the history
  • Loading branch information
thorn0 committed Sep 19, 2015
1 parent 2e53208 commit 6519bb3
Show file tree
Hide file tree
Showing 12 changed files with 296 additions and 195 deletions.
14 changes: 14 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# http://editorconfig.org
root = true

[*]
indent_style = space
indent_size = 4
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true

[package.json]
indent_style = space
indent_size = 2
end_of_line = lf
26 changes: 26 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"rules": {
"indent": [
2,
4
],
"quotes": [
2,
"single"
],
"linebreak-style": [
2,
"unix"
],
"semi": [
2,
"always"
]
},
"env": {
"es6": true,
"node": true
},
"extends": "eslint:recommended",
"parser": "babel-eslint"
}
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/node_modules/
/node_modules/
/lib/
4 changes: 0 additions & 4 deletions .jshintrc

This file was deleted.

5 changes: 5 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/src/
/test/
.gitignore
.eslintrc
.editorconfig
4 changes: 4 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## v2.0.0, 2015-09-xx

* forked from jamesarosen/date-with-offset

## v1.1.0, 2013-09-07

* add `DateWithOffset.prototype.toJSON`
Expand Down
1 change: 1 addition & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
Copyright 2013 James A. Rosen
Copyright 2015 Georgii Dolzhykov

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
9 changes: 0 additions & 9 deletions Makefile

This file was deleted.

54 changes: 40 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,29 @@
# Timezoned Date

```javascript
var TimezonedDate = require('timezoned-date');
console.log(new Date());
// Sat Sep 19 2015 02:39:56 GMT+0300 (Finland Daylight Time)
global.Date = TimezonedDate.makeConstructor(240);
console.log(new Date());
// Sat Sep 19 2015 03:39:56 GMT+0400
```

Works great with [jsdom](https://github.com/tmpvar/jsdom):

```javascript
jsdom.env({
created: function(err, window) {
window.Date = TimezonedDate.makeConstructor(240);
},
// ...
});
```

*README TBD*

*Pre-fork README with minor changes follows.*

# Date With Offset

In JavaScript, all `Date`s have a local time zone. On my computer:
Expand All @@ -16,23 +42,23 @@ now.toISOString();
```

Unfortunately, you can't pass around an actual `Date` in any other time zone.
Instead, create a `DateWithOffset`:
Instead, create a `TimezonedDate`:

```javascript
var nowInUTC = new DateWithOffset(0);
var nowInUTC = new TimezonedDate(0);
// Sun Apr 14 2013 16:49:16 GMT+0000
```

## Creating `DateWithOffset`s
## Creating `TimezonedDate`s

The `DateWithOffset` constructor works just like the `Date` constructor, but
The `TimezonedDate` constructor works just like the `Date` constructor, but
the *last* argument is always the offset from UTC in minutes. Some examples:

```javascript
var nowInParis = new DateWithOffset(60);
var nowInParis = new TimezonedDate(60);
// Sun Apr 14 2013 17:49:16 GMT+0100

var theSameTimeInMelbourne = new DateWithOffset(nowInParis, 600);
var theSameTimeInMelbourne = new TimezonedDate(nowInParis, 600);
// Mon Apr 15 2013 02:49:16 GMT+1000
```

Expand All @@ -42,24 +68,24 @@ If the first argument is a String and contains an offset end with "Z",
it is treated as UTC time:

```
var newYearsGMTInBoston = new DateWithOffset("Jan 1 2013 00:00Z", -300);
var newYearsGMTInBoston = new TimezonedDate("Jan 1 2013 00:00Z", -300);
// Mon Dec 31 2012 19:00:00 GMT-0500
```

If it's a String and doesn't contain an offset of end with "Z", it is treated
as local to the given offset:

```
var newYearsInBoston = new DateWithOffset("Jan 1 2013 00:00", -300);
var newYearsInBoston = new TimezonedDate("Jan 1 2013 00:00", -300);
// Tue Jan 01 2013 00:00:00 GMT-0500
```

Similarly, `DateWithOffset`s created with individual year, month, and day
Similarly, `TimezonedDate`s created with individual year, month, and day
(and, optionally, hours, minutes, seconds, and milliseconds) arguments are
treated as local to the given offset:

```
var newYearsInChicago = new DateWithOffset(2013, 0, 1, -360);
var newYearsInChicago = new TimezonedDate(2013, 0, 1, -360);
```

**Note** this behavior differs from that of the normal `Date` constructor,
Expand All @@ -70,7 +96,7 @@ environment).

The last argument can be a `Number` (as above) or anything that responds to
`valueOf`. If you have richer time zone objects, you can pass them directly
into `new DateWithOffset`:
into `new TimezonedDate`:

```javascript
var tokyo = {
Expand All @@ -79,7 +105,7 @@ var tokyo = {
valueOf: function() { return 540; }
};

var nowInTokyo = new DateWithOffset(now, tokyo);
var nowInTokyo = new TimezonedDate(now, tokyo);
// Mon Apr 15 2013 01:49:16 GMT+0900
```
***Note***: the offset is that between *this* object and *UTC*, which means
Expand All @@ -90,7 +116,7 @@ returns.

## Compatibility with `Date`

You can use a `DateWithOffset` anywhere you use a `Date`:
You can use a `TimezonedDate` anywhere you use a `Date`:

```javascript
nowInUTC.getHours(); // 16
Expand All @@ -114,7 +140,7 @@ nowInTokyo.offset().toString();
// "Tokyo (GMT+0900)"
```

Get a new `DateWithOffset` representing the same point in time at a
Get a new `TimezonedDate` representing the same point in time at a
different UTC offset:

```
Expand Down
158 changes: 0 additions & 158 deletions index.js

This file was deleted.

Loading

0 comments on commit 6519bb3

Please sign in to comment.