Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
dm-docs
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
hammonds
dm-docs
Commits
a800443d
Commit
a800443d
authored
9 years ago
by
sveseli
Browse files
Options
Downloads
Patches
Plain Diff
added utility for utc->localtime
parent
bb3c7b80
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/python/dm/common/utility/timeUtility.py
+19
-0
19 additions, 0 deletions
src/python/dm/common/utility/timeUtility.py
with
19 additions
and
0 deletions
src/python/dm/common/utility/timeUtility.py
+
19
−
0
View file @
a800443d
...
@@ -8,6 +8,8 @@ from dm.common.exceptions.invalidArgument import InvalidArgument
...
@@ -8,6 +8,8 @@ from dm.common.exceptions.invalidArgument import InvalidArgument
class
TimeUtility
:
class
TimeUtility
:
UTC_MINUS_LOCAL_TIME
=
None
@classmethod
@classmethod
def
getCurrentGMTimeStamp
(
cls
):
def
getCurrentGMTimeStamp
(
cls
):
"""
Formats GMT timestamp.
"""
"""
Formats GMT timestamp.
"""
...
@@ -39,8 +41,25 @@ class TimeUtility:
...
@@ -39,8 +41,25 @@ class TimeUtility:
raise
InvalidArgument
(
'
Cannot parse input: %s
'
%
ex
)
raise
InvalidArgument
(
'
Cannot parse input: %s
'
%
ex
)
return
tz
.
localize
(
dt
,
is_dst
=
None
)
return
tz
.
localize
(
dt
,
is_dst
=
None
)
@classmethod
def
utcToLocalTime
(
cls
,
utc
):
if
cls
.
UTC_MINUS_LOCAL_TIME
is
None
:
cls
.
UTC_MINUS_LOCAL_TIME
=
(
datetime
.
datetime
.
utcnow
()
-
datetime
.
datetime
.
now
()).
total_seconds
()
localTime
=
utc
-
cls
.
UTC_MINUS_LOCAL_TIME
return
localTime
#######################################################################
#######################################################################
# Testing.
# Testing.
if
__name__
==
'
__main__
'
:
if
__name__
==
'
__main__
'
:
print
TimeUtility
.
toDateTime
(
'
2015-01-03
'
,
'
%Y-%m-%d
'
)
print
TimeUtility
.
toDateTime
(
'
2015-01-03
'
,
'
%Y-%m-%d
'
)
dt0
=
datetime
.
datetime
.
utcnow
()
dt1
=
datetime
.
datetime
.
now
()
ts0
=
time
.
mktime
(
dt0
.
timetuple
())
ts1
=
time
.
mktime
(
dt1
.
timetuple
())
t0
=
time
.
strftime
(
"
%Y/%m/%d %H:%M:%S
"
,
dt0
.
timetuple
())
print
'
UTC:
'
,
t0
,
ts0
t1
=
time
.
strftime
(
"
%Y/%m/%d %H:%M:%S
"
,
dt1
.
timetuple
())
print
'
LOCAL:
'
,
t1
,
ts1
print
'
UTC TO LOCAL:
'
,
TimeUtility
.
utcToLocalTime
(
ts0
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment