@@ -76,7 +76,7 @@ def as_datetime(expression, now, tz='UTC'):
76
76
'''
77
77
return parse (expression , now , tz )
78
78
79
- def parse (expression , now = None , tz = 'UTC' , type = None ):
79
+ def parse (expression , now = None , tz = 'UTC' , type = None , roundDown = True ):
80
80
'''
81
81
the main meat and potatoes of this this whole thing
82
82
takes our datemath expression and does our date math
@@ -123,7 +123,7 @@ def parse(expression, now=None, tz='UTC', type=None):
123
123
if not math or math == '' :
124
124
rettime = time
125
125
126
- rettime = evaluate (math , time , tz )
126
+ rettime = evaluate (math , time , tz , roundDown )
127
127
if type :
128
128
return getattr (rettime , type )
129
129
else :
@@ -139,11 +139,14 @@ def parseTime(timestamp, tz='UTC'):
139
139
return arrow .get (timestamp )
140
140
141
141
142
- def roundDate (now , unit , tz = 'UTC' ):
142
+ def roundDate (now , unit , tz = 'UTC' , roundDown = True ):
143
143
'''
144
144
rounds our date object
145
145
'''
146
- now = now .floor (unit )
146
+ if roundDown :
147
+ now = now .floor (unit )
148
+ else :
149
+ now = now .ceil (unit )
147
150
if debug : print ("roundDate Now: {0}" .format (now ))
148
151
return now
149
152
@@ -161,7 +164,7 @@ def calculate(now, offsetval, unit):
161
164
except Exception as e :
162
165
raise DateMathException ('Unable to calculate date: now: {0}, offsetvalue: {1}, unit: {2} - reason: {3}' .format (now ,offsetval ,unit ,e ))
163
166
164
- def evaluate (expression , now , timeZone = 'UTC' ):
167
+ def evaluate (expression , now , timeZone = 'UTC' , roundDown = True ):
165
168
'''
166
169
evaluates our datemath style expression
167
170
'''
@@ -176,7 +179,7 @@ def evaluate(expression, now, timeZone='UTC'):
176
179
# then we need to round
177
180
next = str (expression [i + 1 ])
178
181
i += 1
179
- now = roundDate (now , unitMap (next ).rstrip ('s' ), timeZone )
182
+ now = roundDate (now , unitMap (next ).rstrip ('s' ), timeZone , roundDown )
180
183
181
184
elif char == '+' or char == '-' :
182
185
val = 0
0 commit comments