clockwork 0.1.4__tar.gz → 0.2.0__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.1.4
3
+ Version: 0.2.0
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
@@ -0,0 +1,4 @@
1
+ from .core import *
2
+
3
+ __version__ = '0.2.0'
4
+ __author__ = 'Zachary Einck <zacharyeinck@gmail.com>'
@@ -325,7 +325,7 @@ class DateBase(object):
325
325
  components = ['%Y-%m-%d']
326
326
  if self.dt.hour + self.dt.second + self.dt.microsecond > 0:
327
327
  components.append('%I:%M:%S.%f %p')
328
- return self.str(' '.join(components))
328
+ return self.__class__.__name__ + '(%s)' % self.str(' '.join(components))
329
329
 
330
330
  def __int__(self):
331
331
  return self.timestamp
@@ -12,7 +12,7 @@ from ._month_end import MonthEnd
12
12
  #| Functions |
13
13
  #╰-------------------------------------------------------------------------╯
14
14
 
15
- def Date(arg=None, normalize=False, week_offset=0):
15
+ def Date(arg=None, normalize=False, format=None, week_offset=0):
16
16
  '''
17
17
  Description
18
18
  ------------
@@ -35,6 +35,8 @@ def Date(arg=None, normalize=False, week_offset=0):
35
35
  • DateBase object or DateBase polymorphism
36
36
  normalize : bool
37
37
  if True, only the year, month, and day are retained (hours, minutes, seconds, microseconds are set to zero)
38
+ format : str
39
+ if 'arg' is a string, this format is used to parse it (e.g. '%Y%m%d %H%S').
38
40
  week_offset : int
39
41
  by default, if a day of the week is supplied (e.g. 'Monday') then the date returned will be that day of the week
40
42
  for the current week. This argument is used to override this behavior by shifting the week backwards or forwards
@@ -70,6 +72,12 @@ def Date(arg=None, normalize=False, week_offset=0):
70
72
  return out
71
73
 
72
74
 
75
+ if format is not None:
76
+ if not isinstance(arg, str):
77
+ raise TypeError(f"When 'format' argument is not None, 'arg' must be a string, not {type(arg)}.")
78
+ arg = DateBase.to_datetime(arg, format=format)
79
+ return Date(arg, normalize=normalize)
80
+
73
81
  if arg is None:
74
82
  dt = datetime.datetime.now()
75
83
  elif hasattr(arg, 'to_pydatetime'): # pandas
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "clockwork"
3
- version = "0.1.4"
3
+ version = "0.2.0"
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"
@@ -1,4 +0,0 @@
1
- from .core import *
2
-
3
- __version__ = '0.1.4'
4
- __author__ = 'Zachary Einck <zacharyeinck@gmail.com>'
File without changes
File without changes
File without changes