Skip to content

Commit

Permalink
Use datetime.isoformat to ensure timezone handling is correct (#987)
Browse files Browse the repository at this point in the history
* Use datetime.isoformat to ensure timezone handling is correct

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Update changelog

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
ksunden and pre-commit-ci[bot] committed Nov 23, 2020
1 parent ac29a11 commit 66f5aaa
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 21 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/).
### Fixed
- Further handling for readonly files
- Improved chopping with axes that span the kept axes removed
- Timezone offset for `wt.kit.TimeStamp.RFC3339`

## [3.3.2]

Expand Down
25 changes: 4 additions & 21 deletions WrightTools/kit/_timestamp.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,9 @@ def __str__(self):
"""Readable representation."""
return self.RFC3339

def __eq__(self, other):
return self.datetime == other.datetime

@property
def date(self):
"""year-month-day."""
Expand Down Expand Up @@ -151,27 +154,7 @@ def RFC3339(self):
__ https://www.ietf.org/rfc/rfc3339.txt
"""
# get timezone offset
delta_sec = time.timezone
m, s = divmod(delta_sec, 60)
h, m = divmod(m, 60)
# timestamp
format_string = "%Y-%m-%dT%H:%M:%S.%f"
out = self.datetime.strftime(format_string)
# timezone
if delta_sec == 0.0:
out += "Z"
else:
if delta_sec > 0:
sign = "+"
elif delta_sec < 0:
sign = "-"

def as_string(num):
return str(np.abs(int(num))).zfill(2)

out += sign + as_string(h) + ":" + as_string(m)
return out
return self.datetime.isoformat()

@property
def RFC5322(self):
Expand Down
1 change: 1 addition & 0 deletions tests/kit/timestamp.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ def test_human():
def test_RFC3339():
ts = wt.kit.TimeStamp()
assert ts.RFC3339
assert wt.kit.timestamp_from_RFC3339(ts.RFC3339) == ts


def test_RFC5322():
Expand Down

0 comments on commit 66f5aaa

Please sign in to comment.