Skip to content

Commit 831d8fb

Browse files
Merge pull request #26 from nickmaccarthy/issue_25
Issue 25
2 parents be87139 + 22d2810 commit 831d8fb

File tree

10 files changed

+91
-15
lines changed

10 files changed

+91
-15
lines changed

.github/workflows/release.yaml

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
name: Release Packages
2+
on:
3+
release:
4+
types:
5+
- released
6+
jobs:
7+
release-python2:
8+
runs-on: ubuntu-20.04
9+
needs:
10+
- build-python2
11+
steps:
12+
- uses: actions/checkout@v2
13+
- name: install python2 for ubuntu
14+
run: sudo apt install python2
15+
- name: get pip script for python2
16+
run: curl https://bootstrap.pypa.io/pip/2.7/get-pip.py --output get-pip.py
17+
- name: install pip for python2
18+
run: sudo python2 get-pip.py
19+
- name: install requirements for python2
20+
run: pip2 install -r requirements-2.txt
21+
- name: package and upload python2
22+
env:
23+
TWINE_USERNAME: __token__
24+
TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
25+
PYTHON_DATEMATH_VERSION: ${{ github.event.release.tag_name }}
26+
run: |
27+
python2.7 setup.py sdist bdist_wheel
28+
twine upload dist/*
29+
release-python3:
30+
runs-on: ubuntu-20.04
31+
needs:
32+
- build-python3
33+
steps:
34+
- uses: actions/checkout@v2
35+
- name: install requirements for python3
36+
run: pip3 install -r requirements-3.txt
37+
- name: package and upload python3
38+
env:
39+
TWINE_USERNAME: __token__
40+
TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
41+
PYTHON_DATEMATH_VERSION: ${{ github.event.release.tag_name }}
42+
run: |
43+
python3 setup.py sdist bdist_wheel
44+
twine upload dist/*

.github/workflows/tests.yaml

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: Unit Tests
2+
on:
3+
push:
4+
branches:
5+
- master
6+
pull_request:
7+
branches:
8+
- master
9+
jobs:
10+
tests-python2:
11+
runs-on: ubuntu-20.04
12+
steps:
13+
- uses: actions/checkout@v2
14+
- run: sudo apt install python2
15+
- run: curl https://bootstrap.pypa.io/pip/2.7/get-pip.py --output get-pip.py
16+
- run: sudo python2 get-pip.py
17+
- run: pip2 install -r requirements-2.txt
18+
- run: python2 tests.py
19+
tests-python3:
20+
runs-on: ubuntu-20.04
21+
steps:
22+
- uses: actions/checkout@v2
23+
- name: install requirements
24+
run: pip3 install -r requirements-3.txt
25+
- name: run the tests
26+
run: python3 tests.py

.gitignore

+2-6
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
*.pyc
2-
env
3-
venv
4-
arrow_test.py
5-
dm_pretty.py
6-
ranges.py
7-
tztest.py
2+
env*
3+
venv*
84

95
# general things to ignore
106
build/

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Changelog
22

3+
## 1.5.3 (2021-04-16)
4+
* [FIX] [Issue #25](https://github.com/nickmaccarthy/python-datemath/issues/25) - Fixed an issue where if you provided an invalid timestamp, i.e. `datemath('2')` you would not get an DateMathException back. Also bumped dependencies.
5+
36
## 1.5.2 (2020-10-01)
47
* [FIX] [Issue #21](https://github.com/nickmaccarthy/python-datemath/issues/21) - Fixed an issue where if timezone offset was in a datetime string (ISO8601), the timezone of the returned datemath object would be UTC and not the timezone as specified in the datetime string.
58

VERSION.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.5.2
1+
1.5.3

datemath/__init__.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
from .helpers import parse
1+
from .helpers import parse, DateMathException
22

33
def dm(expr, **kwargs):
44
''' does our datemath and returns an arrow object '''
55
return parse(expr, **kwargs)
66

77
def datemath(expr, **kwargs):
88
''' does our datemath and returns a datetime object '''
9-
return parse(expr, **kwargs).datetime
9+
return parse(expr, **kwargs)

datemath/helpers.py

+4
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ def parse(expression, now=None, tz='UTC', type=None, roundDown=True):
136136
math = expression
137137
time = now
138138
else:
139+
if debug: print('parse() - Found and expression that will hit the catchall')
139140
math = ''
140141
time = parseTime(expression, tz)
141142

@@ -174,6 +175,9 @@ def parseTime(timestamp, timezone='UTC'):
174175
ts = ts.replace(tzinfo=timezone)
175176

176177
return ts
178+
else:
179+
if debug: print('parseTime() - Doesnt look like we have a valid timestamp, raise an exception. timestamp={}'.format(timestamp))
180+
raise DateMathException('Valid length timestamp not provide, you gave me a timestamp of "{}", but I need something that has a len() >= 4'.format(timestamp))
177181

178182
def roundDate(now, unit, tz='UTC', roundDown=True):
179183
'''

requirements-2.txt

-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ packaging==16.8
77
pkginfo==1.4.2
88
pyparsing==2.2.0
99
python-dateutil==2.6.0
10-
requests==2.13.0
11-
requests-toolbelt>=0.8.0
1210
six==1.10.0
1311
traceback2==1.4.0
1412
twine>=1.8.1

requirements-3.txt

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
appdirs==1.4.3
22
args==0.1.0
33
arrow==0.15.2
4-
bleach==3.1.2
4+
bleach==3.3.0
55
certifi==2019.9.11
66
chardet==3.0.4
77
clint==0.5.1
88
docutils==0.15.2
99
idna==2.7
1010
linecache2==1.0.0
1111
packaging==16.8
12-
pkginfo==1.4.1
13-
Pygments==2.4.2
12+
pkginfo==1.4.2
13+
Pygments==2.7.4
1414
pyparsing==2.2.0
1515
python-dateutil==2.6.0
1616
readme-renderer==24.0

tests.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
iso8601 = 'YYYY-MM-DDTHH:mm:ssZZ'
1414
class TestDM(unittest.TestCase):
1515

16+
1617
def testParse(self):
1718

1819
# Baisc dates
@@ -154,7 +155,11 @@ def testParse(self):
154155
self.assertRaises(DateMathException, dm, '+1ä')
155156
self.assertRaises(DateMathException, dm, '+1ü')
156157
self.assertRaises(DateMathException, dm, '+1ß')
157-
158+
self.assertRaises(DateMathException, dm, '2')
159+
self.assertRaises(DateMathException, datemath, '2')
160+
self.assertRaises(DateMathException, dm, '123')
161+
self.assertRaises(DateMathException, datemath, '123')
162+
158163
try:
159164
dm('+1,')
160165
except DateMathException as e:

0 commit comments

Comments
 (0)