Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
W
WindEnergyToolbox
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
toolbox
WindEnergyToolbox
Commits
2f9b995b
Commit
2f9b995b
authored
9 years ago
by
mads
Browse files
Options
Downloads
Patches
Plain Diff
support datetime_lists in to_unix
parent
55815321
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
wetb/gtsdf/tests/test_unix_time.py
+17
-6
17 additions, 6 deletions
wetb/gtsdf/tests/test_unix_time.py
wetb/gtsdf/unix_time.py
+7
-4
7 additions, 4 deletions
wetb/gtsdf/unix_time.py
with
24 additions
and
10 deletions
wetb/gtsdf/tests/test_unix_time.py
+
17
−
6
View file @
2f9b995b
...
...
@@ -7,17 +7,28 @@ import unittest
import
numpy
as
np
import
datetime
from
wetb.utils.timing
import
print_time
from
wetb.gtsdf.unix_time
import
to_unix
from
wetb.gtsdf.unix_time
import
to_unix
,
from_unix
class
TestUnixTime
(
unittest
.
TestCase
):
#@print_time
def
r
(
self
,
dt
):
return
[
to_unix
(
dt
)
for
dt
in
dt
]
def
test_to_unix
(
self
):
dt
=
[
datetime
.
datetime
(
2000
,
1
,
1
,
12
,
s
%
60
)
for
s
in
np
.
arange
(
1000000
)]
self
.
r
(
dt
)
self
.
assertEqual
(
to_unix
(
datetime
.
datetime
(
2016
,
2
,
2
,
13
,
6
,
25
)),
1454418385
)
self
.
assertNotEqual
(
to_unix
(
datetime
.
datetime
(
2016
,
2
,
2
,
13
,
6
,
26
)),
1454418385
)
def
test_from_unix
(
self
):
self
.
assertEqual
(
from_unix
(
1454418385
),
datetime
.
datetime
(
2016
,
2
,
2
,
13
,
6
,
25
))
self
.
assertNotEqual
(
from_unix
(
1454418385
),
datetime
.
datetime
(
2016
,
2
,
2
,
13
,
6
,
26
))
# @print_time
# def r(self, dt):
# return [to_unix(dt) for dt in dt]
# def test_to_unix_time(self):
# dt = [datetime.datetime(2000, 1, 1, 12, s % 60) for s in np.arange(1000000)]
# self.r(dt)
if
__name__
==
"
__main__
"
:
#import sys;sys.argv = ['', 'Test.testName']
...
...
This diff is collapsed.
Click to expand it.
wetb/gtsdf/unix_time.py
+
7
−
4
View file @
2f9b995b
...
...
@@ -2,11 +2,14 @@ from datetime import datetime, date
import
numpy
as
np
timestamp0
=
datetime
.
utcfromtimestamp
(
0
)
def
to_unix
(
dateTime
):
#return dateTime.timestamp() + 3600
return
(
dateTime
-
timestamp0
).
total_seconds
()
#return (dateTime - datetime.utcfromtimestamp(0)).total_seconds()
def
to_unix
(
dateTime
):
try
:
return
(
dateTime
-
timestamp0
).
total_seconds
()
except
:
if
hasattr
(
dateTime
,
"
__len__
"
):
return
[(
dt
-
timestamp0
).
total_seconds
()
for
dt
in
dateTime
]
raise
def
from_unix_old
(
sec
):
if
np
.
isnan
(
sec
):
...
...
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