Skip to content

Commit d7646d1

Browse files
author
ASU
committed
v0.2.9: added use_zule to iso_date_basic
1 parent b6745b3 commit d7646d1

File tree

2 files changed

+11
-13
lines changed

2 files changed

+11
-13
lines changed

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
__author__ = 'ASU'
77

88
# Bump up this version
9-
VERSION = '0.2.8'
9+
VERSION = '0.2.9'
1010

1111
basedir = path.abspath(path.dirname(__file__))
1212

tsx/ts.py

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ def __eq__(self, o: "dTS") -> bool:
157157
def __radd__(self, other):
158158
return self.__add__(other)
159159

160+
160161
@total_ordering
161162
class BaseTS(ABC, metaclass=ABCMeta):
162163
@classmethod
@@ -347,21 +348,20 @@ def isoformat(self, sep='T', timespec='auto') -> str:
347348

348349
iso = isoformat
349350

350-
def iso_date(self) -> str:
351+
def iso_date(self, sep="-", use_zulu: bool = False) -> str:
351352
"""
352353
Returns Extended ISO date format.
353354
Example: 2021-01-01
354355
"""
355-
s = self.as_dt().strftime("%Y-%m-%d")
356-
return s
356+
zulu_designator = "Z" if use_zulu else ""
357+
return self.as_dt().strftime(f"%Y{sep}%m{sep}%d{zulu_designator}")
357358

358-
def iso_date_basic(self) -> str:
359+
def iso_date_basic(self, use_zulu: bool = False) -> str:
359360
"""
360361
Returns Basic ISO date format.
361362
Example: 20210101
362363
"""
363-
s = self.as_dt().strftime("%Y%m%d")
364-
return s
364+
return self.iso_date(sep="", use_zulu=use_zulu)
365365

366366
def iso_tz(self, tz: Union[str, tzinfo]) -> str:
367367
"""
@@ -372,8 +372,7 @@ def iso_tz(self, tz: Union[str, tzinfo]) -> str:
372372
tz = pytz.timezone(tz)
373373
dt = self.as_dt(tz=tz)
374374
s = dt.isoformat()
375-
s = s.replace("+00:00", "Z")
376-
return s
375+
return s.replace("+00:00", "Z")
377376

378377
def iso_basic(self, sep="-", use_zulu: bool = False) -> str:
379378
"""
@@ -382,8 +381,7 @@ def iso_basic(self, sep="-", use_zulu: bool = False) -> str:
382381
"""
383382
dt = self.as_dt()
384383
zulu_designator = "Z" if use_zulu else ""
385-
s = dt.strftime(f"%Y%m%d{sep}%H%M%S{zulu_designator}")
386-
return s
384+
return dt.strftime(f"%Y%m%d{sep}%H%M%S{zulu_designator}")
387385

388386
def as_sec(self) -> "iTS":
389387
"""
@@ -693,7 +691,6 @@ def __lt__(self, o: object) -> bool:
693691
return False
694692

695693

696-
697694
class TSMsec(TS):
698695
def __new__(cls, ts: Union[int, float, str], prec: Literal["s", "ms"] = "ms"):
699696
if isinstance(ts, TS):
@@ -808,7 +805,7 @@ def __eq__(self, o: object) -> bool:
808805
if isinstance(o, BaseTS):
809806
return int.__eq__(self.as_nsec(), o.as_nsec())
810807
if isinstance(o, Real):
811-
return int.__eq__(int(self),o)
808+
return int.__eq__(int(self), o)
812809
return False
813810

814811
def __ne__(self, o: object) -> bool:
@@ -819,6 +816,7 @@ def __hash__(self) -> int:
819816
nsec = self.as_nsec()
820817
return int.__hash__(nsec)
821818

819+
822820
class iTS(iBaseTS):
823821
"""
824822
Represents Unix timestamp in seconds since Epoch, by default in UTC.

0 commit comments

Comments
 (0)