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 6baf8c77
authored
Jul 08, 2014
by
Jan Aagaard Meier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
mend
1 parent
107098db
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
52 additions
and
0 deletions
test/timezone.test.js
test/timezone.test.js
0 → 100644
View file @
6baf8c7
"use strict"
;
var
chai
=
require
(
'chai'
)
,
expect
=
chai
.
expect
,
Support
=
require
(
__dirname
+
'/support'
)
,
dialect
=
Support
.
getTestDialect
()
,
Transaction
=
require
(
__dirname
+
'/../lib/transaction'
)
,
Sequelize
=
require
(
__dirname
+
'/../index'
)
,
Promise
=
Sequelize
.
Promise
,
sinon
=
require
(
'sinon'
);
if
(
dialect
!==
'sqlite'
)
{
// Sqlite does not support setting timezone
describe
.
only
(
Support
.
getTestDialectTeaser
(
'Timezone'
),
function
()
{
beforeEach
(
function
()
{
this
.
sequelizeWithTimezone
=
Support
.
createSequelizeInstance
({
timezone
:
'+07:00'
,
dialect
:
dialect
});
});
it
(
'returns the same value for current timestamp'
,
function
()
{
var
query
=
"SELECT now() as now"
;
return
Promise
.
all
([
this
.
sequelize
.
query
(
query
),
this
.
sequelizeWithTimezone
.
query
(
query
)
]).
spread
(
function
(
now1
,
now2
)
{
expect
(
now1
[
0
].
now
.
getTime
()).
to
.
be
.
closeTo
(
now2
[
0
].
now
.
getTime
(),
50
);
});
});
if
(
Support
.
dialectIsMySQL
())
{
it
(
'handles existing timestamps'
,
function
()
{
var
NormalUser
=
this
.
sequelize
.
define
(
'user'
,
{})
,
TimezonedUser
=
this
.
sequelizeWithTimezone
.
define
(
'user'
,
{});
return
this
.
sequelize
.
sync
({
force
:
true
}).
bind
(
this
).
then
(
function
()
{
return
NormalUser
.
create
({});
}).
then
(
function
(
normalUser
)
{
this
.
normalUser
=
normalUser
;
return
TimezonedUser
.
find
(
normalUser
.
id
);
}).
then
(
function
(
timezonedUser
)
{
// Expect 7 hours difference, in milliseconds.
// This difference is expected since two instances, configured for each their timezone is trying to read the same timestamp
// this test does not apply to PG, since it stores the timezone along with the timestamp.
expect
(
this
.
normalUser
.
createdAt
.
getTime
()
-
timezonedUser
.
createdAt
.
getTime
()
).
to
.
be
.
closeTo
(
60
*
60
*
7
*
1000
,
50
);
});
});
}
});
}
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