Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
grumpy
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
grumpy
Commits
68500fad
Commit
68500fad
authored
Feb 04, 2017
by
YOU
Committed by
Dylan Trotter
Feb 04, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add struct_time, gmtime, localtime, mktime, strftime to lib/time (#219)
parent
348f0380
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
96 additions
and
1 deletion
+96
-1
lib/time.py
lib/time.py
+96
-1
No files found.
lib/time.py
View file @
68500fad
...
...
@@ -14,7 +14,74 @@
"""Time access and conversions."""
from
__go__.time
import
Now
,
Second
,
Sleep
# pylint: disable=g-multiple-import
from
__go__.time
import
Now
,
Second
,
Sleep
,
Unix
,
Date
,
UTC
# pylint: disable=g-multiple-import
_strftime_directive_map
=
{
'%'
:
'%'
,
'a'
:
'Mon'
,
'A'
:
'Monday'
,
'b'
:
'Jan'
,
'B'
:
'January'
,
'c'
:
NotImplemented
,
'd'
:
'02'
,
'H'
:
'15'
,
'I'
:
'03'
,
'j'
:
NotImplemented
,
'L'
:
'.000'
,
'm'
:
'01'
,
'M'
:
'04'
,
'p'
:
'PM'
,
'S'
:
'05'
,
'U'
:
NotImplemented
,
'W'
:
NotImplemented
,
'w'
:
NotImplemented
,
'X'
:
NotImplemented
,
'x'
:
NotImplemented
,
'y'
:
'06'
,
'Y'
:
'2006'
,
'Z'
:
'MST'
,
'z'
:
'-0700'
,
}
class
struct_time
(
tuple
):
#pylint: disable=invalid-name,missing-docstring
def
__init__
(
self
,
args
):
super
(
struct_time
,
self
).
__init__
(
tuple
,
args
)
self
.
tm_year
=
self
[
0
]
self
.
tm_mon
=
self
[
1
]
self
.
tm_mday
=
self
[
2
]
self
.
tm_hour
=
self
[
3
]
self
.
tm_min
=
self
[
4
]
self
.
tm_sec
=
self
[
5
]
self
.
tm_wday
=
self
[
6
]
self
.
tm_yday
=
self
[
7
]
self
.
tm_isdst
=
self
[
8
]
def
__repr__
(
self
):
return
(
"time.struct_time(tm_year=%s, tm_mon=%s, tm_mday=%s, "
"tm_hour=%s, tm_min=%s, tm_sec=%s, tm_wday=%s, "
"tm_yday=%s, tm_isdst=%s)"
)
%
self
def
__str__
(
self
):
return
repr
(
self
)
def
gmtime
(
seconds
=
None
):
t
=
(
Unix
(
seconds
,
0
)
if
seconds
else
Now
()).
UTC
()
return
struct_time
((
t
.
Year
(),
t
.
Month
(),
t
.
Day
(),
t
.
Hour
(),
t
.
Minute
(),
t
.
Second
(),
(
t
.
Weekday
()
+
6
)
%
7
,
t
.
YearDay
(),
0
))
def
localtime
(
seconds
=
None
):
t
=
(
Unix
(
seconds
,
0
)
if
seconds
else
Now
()).
Local
()
return
struct_time
((
t
.
Year
(),
t
.
Month
(),
t
.
Day
(),
t
.
Hour
(),
t
.
Minute
(),
t
.
Second
(),
(
t
.
Weekday
()
+
6
)
%
7
,
t
.
YearDay
(),
0
))
def
mktime
(
t
):
return
float
(
Date
(
t
[
0
],
t
[
1
],
t
[
2
],
t
[
3
],
t
[
4
],
t
[
5
],
0
,
UTC
).
Unix
())
def
sleep
(
secs
):
...
...
@@ -23,3 +90,31 @@ def sleep(secs):
def
time
():
return
float
(
Now
().
UnixNano
())
/
Second
def
strftime
(
format
,
tt
=
None
):
# pylint: disable=missing-docstring,redefined-builtin
t
=
(
Unix
(
int
(
mktime
(
tt
)),
0
)
if
tt
else
Now
()).
Local
()
ret
=
[]
prev
,
n
=
0
,
format
.
find
(
'%'
,
0
,
-
1
)
while
n
!=
-
1
:
ret
.
append
(
format
[
prev
:
n
])
next_ch
=
format
[
n
+
1
]
c
=
_strftime_directive_map
.
get
(
next_ch
)
if
c
is
NotImplemented
:
raise
NotImplementedError
(
'Code: %'
+
next_ch
+
' not yet supported'
)
if
c
:
ret
.
append
(
t
.
Format
(
c
))
else
:
ret
.
append
(
format
[
n
:
n
+
2
])
n
+=
2
prev
,
n
=
n
,
format
.
find
(
'%'
,
n
,
-
1
)
ret
.
append
(
format
[
prev
:])
return
''
.
join
(
ret
)
# TODO: Calculate real value for daylight saving.
daylight
=
0
# TODO: Use local DST instead of ''.
tzname
=
(
Now
().
Zone
()[
0
],
''
)
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