Skip to content

Commit

Permalink
Merge pull request #26 from nickmaccarthy/issue_25
Browse files Browse the repository at this point in the history
Issue 25
  • Loading branch information
nickmaccarthy authored Apr 20, 2021
2 parents be87139 + 22d2810 commit 831d8fb
Show file tree
Hide file tree
Showing 10 changed files with 91 additions and 15 deletions.
44 changes: 44 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Release Packages
on:
release:
types:
- released
jobs:
release-python2:
runs-on: ubuntu-20.04
needs:
- build-python2
steps:
- uses: actions/checkout@v2
- name: install python2 for ubuntu
run: sudo apt install python2
- name: get pip script for python2
run: curl https://bootstrap.pypa.io/pip/2.7/get-pip.py --output get-pip.py
- name: install pip for python2
run: sudo python2 get-pip.py
- name: install requirements for python2
run: pip2 install -r requirements-2.txt
- name: package and upload python2
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
PYTHON_DATEMATH_VERSION: ${{ github.event.release.tag_name }}
run: |
python2.7 setup.py sdist bdist_wheel
twine upload dist/*
release-python3:
runs-on: ubuntu-20.04
needs:
- build-python3
steps:
- uses: actions/checkout@v2
- name: install requirements for python3
run: pip3 install -r requirements-3.txt
- name: package and upload python3
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
PYTHON_DATEMATH_VERSION: ${{ github.event.release.tag_name }}
run: |
python3 setup.py sdist bdist_wheel
twine upload dist/*
26 changes: 26 additions & 0 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Unit Tests
on:
push:
branches:
- master
pull_request:
branches:
- master
jobs:
tests-python2:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
- run: sudo apt install python2
- run: curl https://bootstrap.pypa.io/pip/2.7/get-pip.py --output get-pip.py
- run: sudo python2 get-pip.py
- run: pip2 install -r requirements-2.txt
- run: python2 tests.py
tests-python3:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
- name: install requirements
run: pip3 install -r requirements-3.txt
- name: run the tests
run: python3 tests.py
8 changes: 2 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
*.pyc
env
venv
arrow_test.py
dm_pretty.py
ranges.py
tztest.py
env*
venv*

# general things to ignore
build/
Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changelog

## 1.5.3 (2021-04-16)
* [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.

## 1.5.2 (2020-10-01)
* [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.

Expand Down
2 changes: 1 addition & 1 deletion VERSION.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.5.2
1.5.3
4 changes: 2 additions & 2 deletions datemath/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from .helpers import parse
from .helpers import parse, DateMathException

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

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

This comment has been minimized.

Copy link
@olivierlefloch

olivierlefloch Apr 22, 2021

I believe this change means datemath() now returns an arrow object instead of a datetime?

This comment has been minimized.

Copy link
@nickmaccarthy

nickmaccarthy Apr 26, 2021

Author Owner

Apologies. This is a bug, I will be fixing this shortly

This comment has been minimized.

Copy link
@nickmaccarthy

nickmaccarthy Apr 26, 2021

Author Owner

@olivierlefloch - v1.5.5 should be on pypi now which addresses this. Let me know if you have issues. Feel free to open an issue if you do.

This comment has been minimized.

Copy link
@olivierlefloch

olivierlefloch May 23, 2021

Sorry for the delay in acknowledging this, I greatly appreciate the promptness with which you resolved this and we upgraded immediately!

4 changes: 4 additions & 0 deletions datemath/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ def parse(expression, now=None, tz='UTC', type=None, roundDown=True):
math = expression
time = now
else:
if debug: print('parse() - Found and expression that will hit the catchall')
math = ''
time = parseTime(expression, tz)

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

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

def roundDate(now, unit, tz='UTC', roundDown=True):
'''
Expand Down
2 changes: 0 additions & 2 deletions requirements-2.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ packaging==16.8
pkginfo==1.4.2
pyparsing==2.2.0
python-dateutil==2.6.0
requests==2.13.0
requests-toolbelt>=0.8.0
six==1.10.0
traceback2==1.4.0
twine>=1.8.1
Expand Down
6 changes: 3 additions & 3 deletions requirements-3.txt
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
appdirs==1.4.3
args==0.1.0
arrow==0.15.2
bleach==3.1.2
bleach==3.3.0
certifi==2019.9.11
chardet==3.0.4
clint==0.5.1
docutils==0.15.2
idna==2.7
linecache2==1.0.0
packaging==16.8
pkginfo==1.4.1
Pygments==2.4.2
pkginfo==1.4.2
Pygments==2.7.4
pyparsing==2.2.0
python-dateutil==2.6.0
readme-renderer==24.0
Expand Down
7 changes: 6 additions & 1 deletion tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
iso8601 = 'YYYY-MM-DDTHH:mm:ssZZ'
class TestDM(unittest.TestCase):


def testParse(self):

# Baisc dates
Expand Down Expand Up @@ -154,7 +155,11 @@ def testParse(self):
self.assertRaises(DateMathException, dm, '+1ä')
self.assertRaises(DateMathException, dm, '+1ü')
self.assertRaises(DateMathException, dm, '+1ß')

self.assertRaises(DateMathException, dm, '2')
self.assertRaises(DateMathException, datemath, '2')
self.assertRaises(DateMathException, dm, '123')
self.assertRaises(DateMathException, datemath, '123')

try:
dm('+1,')
except DateMathException as e:
Expand Down

0 comments on commit 831d8fb

Please sign in to comment.