clockwork 0.3.1__tar.gz → 0.3.3__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: clockwork
3
- Version: 0.3.1
3
+ Version: 0.3.3
4
4
  Summary: Toolkit for time-related operations including scheduling, logging, date manipulation, and more.
5
5
  Home-page: https://github.com/zteinck/clockwork
6
6
  License: MIT
@@ -8,5 +8,5 @@ from .utils import (
8
8
  date_format_to_regex,
9
9
  )
10
10
 
11
- __version__ = '0.3.1'
11
+ __version__ = '0.3.3'
12
12
  __author__ = 'Zachary Einck <zacharyeinck@gmail.com>'
@@ -119,7 +119,7 @@ class Timestamp(object):
119
119
  # Otherwise, 'other' is assumed to be a delta and the resulting
120
120
  # Timestamp object is returned.
121
121
  delta = self._build_delta(other)
122
- return self._to_timestamp(func(self, delta))
122
+ return self._make_base(func(self, delta))
123
123
 
124
124
  return wrapper
125
125
 
@@ -274,8 +274,8 @@ class Timestamp(object):
274
274
 
275
275
  @property
276
276
  def date(self):
277
- ''' return the date component as a 'datetime.date' object '''
278
- return self.dt.date()
277
+ ''' to_date() alias '''
278
+ return self.to_date()
279
279
 
280
280
 
281
281
  @property
@@ -286,7 +286,7 @@ class Timestamp(object):
286
286
 
287
287
  @property
288
288
  def pandas(self):
289
- ''' return as a pd.Timestamp object '''
289
+ ''' to_pandas() alias '''
290
290
  return self.to_pandas()
291
291
 
292
292
 
@@ -296,28 +296,16 @@ class Timestamp(object):
296
296
  return self.to_string('%Y-%m-%d')
297
297
 
298
298
 
299
- @property
300
- def sql_server(self):
301
- ''' ymd alias '''
302
- return self.ymd
303
-
304
-
305
- @property
306
- def oracle(self):
307
- ''' string in DD-%b-YY (e.g. 30-Sep-19) format '''
308
- return self.to_string('%d-%b-%y')
309
-
310
-
311
299
  @property
312
300
  def timestamp(self):
313
- ''' returns a timestamp[float] '''
314
- return self.to_pandas().timestamp()
301
+ ''' to_timestamp() alias '''
302
+ return self.to_timestamp()
315
303
 
316
304
 
317
305
  @property
318
306
  def time(self):
319
- ''' returns the time component (datetime.time) '''
320
- return self.dt.time()
307
+ ''' to_time() alias '''
308
+ return self.to_time()
321
309
 
322
310
 
323
311
  @property
@@ -505,7 +493,7 @@ class Timestamp(object):
505
493
 
506
494
 
507
495
  def __float__(self):
508
- return self.timestamp
496
+ return self.to_timestamp()
509
497
 
510
498
 
511
499
  def __int__(self):
@@ -571,22 +559,42 @@ class Timestamp(object):
571
559
 
572
560
  def copy(self):
573
561
  ''' returns a deep copy of self '''
574
- dt = deep_copy(self.dt)
562
+ dt = self.to_datetime()
575
563
  return self.__class__(dt)
576
564
 
577
565
 
566
+ def to_datetime(self):
567
+ ''' returns a copy of the underlying datetime.datetime object '''
568
+ return deep_copy(self.dt)
569
+
570
+
578
571
  def to_pandas(self):
579
572
  ''' return as a pd.Timestamp object '''
580
573
  return pd.to_datetime(self.dt)
581
574
 
582
575
 
576
+ def to_timestamp(self):
577
+ ''' returns timestamp expressed in seconds '''
578
+ return self.to_pandas().timestamp()
579
+
580
+
581
+ def to_date(self):
582
+ ''' return the date component as a 'datetime.date' object '''
583
+ return self.dt.date()
584
+
585
+
586
+ def to_time(self):
587
+ ''' returns the time component as a 'datetime.time' object '''
588
+ return self.dt.time()
589
+
590
+
583
591
  def to_string(self, fmt):
584
592
  ''' strftime alias '''
585
593
  return self.strftime(fmt)
586
594
 
587
595
 
588
596
  def str(self, *args, **kwargs):
589
- ''' strftime alias '''
597
+ ''' to_string() alias '''
590
598
  return self.to_string(*args, **kwargs)
591
599
 
592
600
 
@@ -637,7 +645,7 @@ class Timestamp(object):
637
645
 
638
646
  def _shift(self, **kwargs):
639
647
  delta = self._build_delta(kwargs)
640
- return self._to_timestamp(self.dt + delta)
648
+ return self._make_base(self.dt + delta)
641
649
 
642
650
 
643
651
  def shift(self, **kwargs):
@@ -710,7 +718,7 @@ class Timestamp(object):
710
718
  #╰-------------------------------------------------------------------------╯
711
719
 
712
720
  @staticmethod
713
- def _to_timestamp(*args, **kwargs):
721
+ def _make_base(*args, **kwargs):
714
722
  return Timestamp(*args, **kwargs)
715
723
 
716
724
 
@@ -901,7 +909,8 @@ class Timestamp(object):
901
909
 
902
910
  return pd.to_datetime(arg, **kwargs).to_pydatetime()
903
911
 
904
- if isinstance(arg, cls):
912
+ # Timestamp instance (or subclass)
913
+ if isinstance(arg, Timestamp):
905
914
  return arg.dt
906
915
 
907
916
  # pandas object
@@ -914,10 +923,13 @@ class Timestamp(object):
914
923
  if isinstance(arg, datetime.date):
915
924
  return cls._normalize(arg)
916
925
 
926
+ # timestamp expressed in seconds
917
927
  if isinstance(arg, (float, int)):
918
- # timestamp expressed in seconds
919
- # return datetime.datetime.fromtimestamp(arg)
920
- return pd.to_datetime(arg, unit='s').to_pydatetime()
928
+ # local time zone by default
929
+ return datetime.datetime.fromtimestamp(arg)
930
+
931
+ # UTC by default
932
+ # return pd.to_datetime(arg, unit='s').to_pydatetime()
921
933
 
922
934
  raise TypeError(
923
935
  f"'arg' of type <{type(arg).__name__}> "
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "clockwork"
3
- version = "0.3.1"
3
+ version = "0.3.3"
4
4
  description = "Toolkit for time-related operations including scheduling, logging, date manipulation, and more."
5
5
  authors = ["Zachary Einck <zacharyeinck@gmail.com>"]
6
6
  license = "MIT"
File without changes
File without changes
File without changes