Skip to content

Commit 8ae9eca

Browse files
author
Nick MacCarthy
committed
chore: cleanup
1 parent 47a0ce1 commit 8ae9eca

File tree

1 file changed

+0
-42
lines changed

1 file changed

+0
-42
lines changed

datemath/helpers.py

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,3 @@
1-
'''
2-
A basic utility module for parsing math like strings relating to dates
3-
4-
This is inspired by Date Math features in elasticsearch and aims to replicate the same functionality for python.
5-
6-
DateMath (datemath or dm) suppor addition, subtraction and rounding at various granularities of "units" (a map of units to their shorthand is below for reference).
7-
Expressions can be chanied together and are read left to right. '+' and '-' denote addition and subtraction while '/' denotes 'round', in this case is a 'round down' or floor.
8-
Round requires a unit (/d), while addition and subtraction require an integer value and a unit (+1d). Whitespace is not allowed in the expression. Absolute datetimes with datemath
9-
can be made as well, with the datetime and datemath expressions delinated by '||' - example '2015-01-01||+1d' == '2015-01-02'
10-
11-
12-
Maps:
13-
14-
y or Y = 'year'
15-
M = 'month'
16-
m = 'minute'
17-
d or D = 'day'
18-
w = 'week'
19-
h or H = 'hour'
20-
s or S = 'second'
21-
22-
Examples:
23-
24-
Assuming our datetime is currently: '2016-01-01T00:00:00-00:00'
25-
26-
Expression: Result:
27-
now-1h 2015-12-31T23:00:00+00:00
28-
now-1y 2015-01-01T00:00:00+00:00
29-
now+1y+2d 2017-01-03T00:00:00+00:00
30-
now+12h 2016-01-01T12:00:00+00:00
31-
now+1d/d 2016-01-03T00:00:00+00:00
32-
+2h 2016-01-01T02:00:00+00:00
33-
+1h/h 2016-01-01T02:00:00+00:00
34-
now+1w/w 2016-01-11T00:00:00+00:00
35-
now/d+7d+12h 2016-01-08T12:00:00+00:00
36-
2016-01-01||+1d 2016-01-02T00:00:00+00:00
37-
2015-01-01||+2w 2015-01-15T00:00:00+00:00
38-
39-
'''
40-
411
from __future__ import annotations
422

433
import os
@@ -250,8 +210,6 @@ def evaluate(expression: str, now: Arrow, timeZone: str = 'UTC', roundDown: bool
250210
if debug: print('\n\n')
251211
return now
252212

253-
254-
255213
if __name__ == "__main__":
256214
if debug: print('NOW: {0}'.format(arrow.utcnow()))
257215
if debug: print('\n\n')

0 commit comments

Comments
 (0)