Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
openpyxl
openpyxl
Commits
dafd90d3d078
Commit
242e8edd
authored
Feb 12, 2021
by
nmartensen
Browse files
optimize getting the epoch
--HG-- branch : 3.0
parent
92f444de400a
Pipeline
#17902
failed with stage
in 4 minutes and 25 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
openpyxl/utils/datetime.py
View file @
dafd90d3
...
...
@@ -64,12 +64,6 @@ def from_ISO8601(formatted_string):
return
dt
def
_get_epoch
(
offset
):
if
offset
==
CALENDAR_MAC_1904
:
return
MAC_EPOCH
return
WINDOWS_EPOCH
def
to_excel
(
dt
,
offset
=
CALENDAR_WINDOWS_1900
):
if
isinstance
(
dt
,
datetime
.
time
):
return
time_to_days
(
dt
)
...
...
@@ -77,7 +71,8 @@ def to_excel(dt, offset=CALENDAR_WINDOWS_1900):
return
timedelta_to_days
(
dt
)
if
isnan
(
dt
.
year
):
# Pandas supports Not a Date
return
jul
=
(
datetime
.
datetime
(
dt
.
year
,
dt
.
month
,
dt
.
day
)
-
_get_epoch
(
offset
)).
days
epoch
=
offset
==
CALENDAR_WINDOWS_1900
and
WINDOWS_EPOCH
or
MAC_EPOCH
jul
=
(
datetime
.
datetime
(
dt
.
year
,
dt
.
month
,
dt
.
day
)
-
epoch
).
days
if
jul
<=
60
and
offset
==
CALENDAR_WINDOWS_1900
:
jul
-=
1
if
hasattr
(
dt
,
'time'
):
...
...
@@ -94,7 +89,8 @@ def from_excel(value, offset=CALENDAR_WINDOWS_1900):
return
days_to_time
(
diff
)
if
1
<
value
<
60
and
offset
==
CALENDAR_WINDOWS_1900
:
day
+=
1
return
_get_epoch
(
offset
)
+
datetime
.
timedelta
(
days
=
day
)
+
diff
epoch
=
offset
==
CALENDAR_WINDOWS_1900
and
WINDOWS_EPOCH
or
MAC_EPOCH
return
epoch
+
datetime
.
timedelta
(
days
=
day
)
+
diff
class
GMT
(
tzinfo
):
...
...
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