Skip to content

Commit 231f57d

Browse files
committed
v.1.5.2
1 parent 2fec26f commit 231f57d

File tree

1 file changed

+34
-11
lines changed

1 file changed

+34
-11
lines changed

README.md

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
[![Build Status](https://travis-ci.org/nickmaccarthy/python-datemath.svg?branch=master)](https://travis-ci.org/nickmaccarthy/python-datemath.svg?branch=master)
22

3+
# Python Datemath
34

4-
# What?
5+
## What?
56
A date math (aka datemath) parser compatiable with the elasticsearch 'date math' format
67

7-
# Why?
8+
## Why?
89
Working with date objects in python has always been interesting. Having a background in php, I have been looking for quite some time ( no pun intended ) for a way to do date time interpolation similar to php's ```strtotime()``` function. While the arrow module comes close, I needed something that could turn date math type strings into datetime objects for use in tattle.io and other projects I use in elasticsearch. I have found even more uses for it, including AWS cloudwatch and various other projects and hopefully you will too.
910

10-
# What is date math ?
11+
## What is date math ?
1112
Date Math is the short hand arithmetic to find relative time to fixed moments in date and time. Similar to the SOLR date math format, Elasticsearch has its own built in format for short hand date math and this module aims to support that same coverage in python.
1213

1314
Documentation from elasticsearch:
@@ -25,7 +26,7 @@ http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/mapping-da
2526
2627
> Note, when doing range type searches, and the upper value is inclusive, the rounding will properly be rounded to the ceiling instead of flooring it.
2728
28-
# Unit Maps
29+
## Unit Maps
2930
```
3031
y or Y = 'year'
3132
M = 'month'
@@ -36,11 +37,11 @@ h or H = 'hour'
3637
s or S = 'second'
3738
```
3839

39-
# Install
40+
## Install
4041
```python
4142
pip install python-datemath
4243
```
43-
# Examples
44+
## Examples
4445
Assuming our datetime is currently: '2016-01-01T00:00:00-00:00'
4546
```
4647
Expression: Result:
@@ -62,7 +63,7 @@ now/d 2016-01-01T23:59:59+00:00
6263
now/Y 2016-12-31T23:59:59+00:00
6364
```
6465

65-
# Usage
66+
## Usage
6667
By default datemath return an arrow date object representing your timestamp.
6768

6869
```
@@ -138,11 +139,17 @@ If you want a Epoch timestamp back instead, we can do that.
138139
1453676321
139140
```
140141

141-
# What timezone are my objects in?
142-
By default all objects returned by datemath are in UTC. If you want them them in a different timezone, just pass along the ```tz``` argument.
143-
Timezone list can be found here: https://gist.github.com/pamelafox/986163
142+
## What timezone are my objects in?
143+
By default all object returned by datemath are in UTC.
144+
145+
If you want them them back in a different timezone, just pass along the ```tz``` argument. Timezone list can be found here: https://gist.github.com/pamelafox/986163
146+
147+
If you provide a timezone offset in your timestring, datemath will return your time object as that timezone offset in the string.
148+
149+
Note - currently timestrings with a timezone offset and the usage of the ```tz``` argument will result in the time object being returned with the timezone of what was in the timezone offset in the original string
144150
```
145-
from datemath import dm
151+
>>> from datemath import dm
152+
>>>
146153
>>> dm('now')
147154
<Arrow [2016-01-26T01:00:53.601088+00:00]>
148155
>>>
@@ -154,8 +161,24 @@ from datemath import dm
154161
>>>
155162
>>> dm('2017-10-20 09:15:20', tz='US/Pacific')
156163
<Arrow [2017-10-20T09:15:20.000000-08:00]>
164+
>>>
165+
>>> # Timestring with TZ offset in the string (ISO8601 format only)
166+
>>> dm('2016-01-01T00:00:00-05:00')
167+
<Arrow [2016-01-01T00:00:00-05:00]>
168+
>>>
169+
>>> # Timestring with TZooffset with datemath added (again, TS must be in ISO8601)
170+
>>> dm('2016-01-01T00:00:00-05:00||+2d+3h+5m')
171+
<Arrow [2016-01-03T03:05:00-05:00]>
172+
>>>
173+
>>> # Note, timestrings with TZ offsets will be returned as the timezone of the offset in the string even if the "tz" option is used.
174+
>>> dm('2016-01-01T00:00:00-05:00', tz='US/Central')
175+
<Arrow [2016-01-01T00:00:00-05:00]>
176+
>>>
157177
```
158178

179+
## Debugging
180+
If you would like more verbose output to debug the process of what datemath is doing, simply set `export DATEMATH_DEBUG=true` in your shell then run some datemath tests. To stop debugging, run `unset DATEMATH_DEBUG`.
181+
159182
## Changes
160183
See CHANGELOG.md
161184

0 commit comments

Comments
 (0)