Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
public
/
sequelize
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
不要怂,就是干,撸起袖子干!
Commit 21883759
authored
May 15, 2015
by
Derek Barnes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add support for named timezones
1 parent
642fbbd2
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
26 additions
and
4 deletions
lib/sql-string.js
package.json
test/integration/timezone.test.js
lib/sql-string.js
View file @
2188375
'use strict'
;
/* jshint -W110 */
var
moment
=
require
(
'moment'
)
var
moment
=
require
(
'moment
-timezone
'
)
,
isArrayBufferView
,
SqlString
=
exports
;
...
...
@@ -165,7 +165,11 @@ SqlString.formatNamedParameters = function(sql, values, timeZone, dialect) {
};
SqlString
.
dateToString
=
function
(
date
,
timeZone
,
dialect
)
{
date
=
moment
(
date
).
utcOffset
(
timeZone
);
if
(
moment
.
tz
.
zone
(
timeZone
))
{
date
=
moment
(
date
).
tz
(
timeZone
);
}
else
{
date
=
moment
(
date
).
utcOffset
(
timeZone
);
}
if
(
dialect
===
'mysql'
||
dialect
===
'mariadb'
)
{
return
date
.
format
(
'YYYY-MM-DD HH:mm:ss'
);
...
...
@@ -200,4 +204,4 @@ SqlString.objectToValues = function(object, timeZone) {
}
return
values
.
join
(
', '
);
};
\ No newline at end of file
};
package.json
View file @
2188375
...
...
@@ -38,6 +38,7 @@
"inflection"
:
"^1.6.0"
,
"lodash"
:
"^3.5.0"
,
"moment"
:
"^2.9.0"
,
"moment-timezone"
:
"^0.3.1"
,
"node-uuid"
:
"~1.4.1"
,
"toposort-class"
:
"~0.3.0"
,
"validator"
:
"^3.34.0"
...
...
test/integration/timezone.test.js
View file @
2188375
...
...
@@ -15,6 +15,9 @@ if (dialect !== 'sqlite') {
this
.
sequelizeWithTimezone
=
Support
.
createSequelizeInstance
({
timezone
:
'+07:00'
});
this
.
sequelizeWithNamedTimezone
=
Support
.
createSequelizeInstance
({
timezone
:
'America/New_York'
});
});
it
(
'returns the same value for current timestamp'
,
function
()
{
...
...
@@ -52,6 +55,21 @@ if (dialect !== 'sqlite') {
expect
(
normalUser
.
createdAt
.
getTime
()
-
this
.
timezonedUser
.
createdAt
.
getTime
()).
to
.
be
.
closeTo
(
60
*
60
*
7
*
1000
,
50
);
});
});
it
(
'handles named timezones'
,
function
()
{
var
NormalUser
=
this
.
sequelize
.
define
(
'user'
,
{})
,
TimezonedUser
=
this
.
sequelizeWithNamedTimezone
.
define
(
'user'
,
{});
return
this
.
sequelize
.
sync
({
force
:
true
}).
bind
(
this
).
then
(
function
()
{
return
TimezonedUser
.
create
({});
}).
then
(
function
(
timezonedUser
)
{
this
.
timezonedUser
=
timezonedUser
;
return
NormalUser
.
find
(
timezonedUser
.
id
);
}).
then
(
function
(
normalUser
)
{
// Expect 7 hours difference, in milliseconds, +/- 1 hour for DST
expect
(
normalUser
.
createdAt
.
getTime
()
-
this
.
timezonedUser
.
createdAt
.
getTime
()).
to
.
be
.
closeTo
(
60
*
60
*
4
*
1000
*
-
1
,
60
*
60
*
1000
);
});
});
}
});
}
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment