Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
F
flot
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
HS-public
flot
Commits
4d295af5
Commit
4d295af5
authored
Mar 16, 2021
by
Igor Kulikov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use moment timezone to handle timezones
parent
0ff0c775
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
4 additions
and
47 deletions
+4
-47
jquery.flot.time.js
src/plugins/jquery.flot.time.js
+4
-47
No files found.
src/plugins/jquery.flot.time.js
View file @
4d295af5
...
...
@@ -132,59 +132,16 @@ API.txt for details.
return
r
.
join
(
""
);
}
// To have a consistent view of time-based data independent of which time
// zone the client happens to be in we need a date-like object independent
// of time zones. This is done through a wrapper that only calls the UTC
// versions of the accessor methods.
function
makeUtcWrapper
(
d
)
{
function
addProxyMethod
(
sourceObj
,
sourceMethod
,
targetObj
,
targetMethod
)
{
sourceObj
[
sourceMethod
]
=
function
()
{
return
targetObj
[
targetMethod
].
apply
(
targetObj
,
arguments
);
};
}
var
utc
=
{
date
:
d
};
// support strftime, if found
if
(
d
.
strftime
!==
undefined
)
{
addProxyMethod
(
utc
,
"strftime"
,
d
,
"strftime"
);
}
addProxyMethod
(
utc
,
"getTime"
,
d
,
"getTime"
);
addProxyMethod
(
utc
,
"setTime"
,
d
,
"setTime"
);
var
props
=
[
"Date"
,
"Day"
,
"FullYear"
,
"Hours"
,
"Milliseconds"
,
"Minutes"
,
"Month"
,
"Seconds"
];
for
(
var
p
=
0
;
p
<
props
.
length
;
p
++
)
{
addProxyMethod
(
utc
,
"get"
+
props
[
p
],
d
,
"getUTC"
+
props
[
p
]);
addProxyMethod
(
utc
,
"set"
+
props
[
p
],
d
,
"setUTC"
+
props
[
p
]);
}
return
utc
;
}
// select time zone strategy. This returns a date-like object tied to the
// desired timezone
function
dateGenerator
(
ts
,
opts
)
{
if
(
opts
.
timezone
===
"browser"
)
{
if
(
!
opts
.
timezone
||
opts
.
timezone
===
"browser"
)
{
return
new
Date
(
ts
);
}
else
if
(
!
opts
.
timezone
||
opts
.
timezone
===
"utc"
)
{
return
makeUtcWrapper
(
new
Date
(
ts
));
}
else
if
(
typeof
timezoneJS
!==
"undefined"
&&
typeof
timezoneJS
.
Date
!==
"undefined"
)
{
var
d
=
new
timezoneJS
.
Date
();
// timezone-js is fickle, so be sure to set the time zone before
// setting the time.
d
.
setTimezone
(
opts
.
timezone
);
d
.
setTime
(
ts
);
return
d
;
}
else
if
(
typeof
moment
!==
"undefined"
&&
typeof
moment
.
tz
!==
"undefined"
)
{
return
moment
(
ts
).
tz
(
opts
.
timezone
).
toDate
();
}
else
{
return
makeUtcWrapper
(
new
Date
(
ts
)
);
return
new
Date
(
ts
);
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
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 comment