Skip to content

Commit

Permalink
Merge pull request #187 from keboola/bug-fix-strtotime
Browse files Browse the repository at this point in the history
Bug fix strtotime
  • Loading branch information
ZdenekSrotyr authored Aug 1, 2024
2 parents 62b78ba + 0083f1d commit a1c8ccd
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ jobs:
target_image: ${{ env.APP_IMAGE}}
tag_as_latest: true
- name: Python Tests
run: docker-compose run --rm ci python -m unittest discover /code/python-sync-actions
run: docker-compose run --rm ci python -v -m unittest discover /code/python-sync-actions
- name: Run Python Functional Tests
working-directory: ./python-sync-actions
run: docker compose run test-calls
Expand Down
4 changes: 2 additions & 2 deletions python-sync-actions/src/user_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def date(self, format_string, timestamp=None):
"""

command = f"php -r 'echo date(\"{format_string}\", {timestamp or 'time()'});'"
command = f"php -r 'echo date(\"{format_string}\", {timestamp or int(time.time())});'"
stdout, stderr = perform_shell_command(command, 'date function')

return stdout
Expand All @@ -118,7 +118,7 @@ def strtotime(self, string, base_time=None):
"""

command = f"php -r 'echo strtotime(\"{string}\", {base_time or 'null'});'"
command = f"php -r 'echo strtotime(\"{string}\", {base_time or int(time.time())});'"
stdout, stderr = perform_shell_command(command, 'strotime function')

return int(stdout)
Expand Down
36 changes: 34 additions & 2 deletions python-sync-actions/tests/test_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ def test_date_strtotime(self):
]
}
expected = '2020-12-30'
result = self.config_helpers.perform_custom_function('test', function_cfg, {})
self.assertEqual(expected, result)
self.execute_function_test(function_cfg, expected)

@freeze_time("2021-01-01")
def test_date_strtotime_timestamp(self):
Expand All @@ -55,6 +54,17 @@ def test_date_strtotime_timestamp(self):
expected = '2020-12-30 00:00:00'
self.execute_function_test(function_cfg, expected)

@freeze_time("2021-01-01")
def test_date_empty_timestamp(self):
function_cfg = {
"function": "date",
"args": [
"Y-m-d H:i:s"
]
}
expected = '2021-01-01 00:00:00'
self.execute_function_test(function_cfg, expected)

@freeze_time("2021-01-01")
def test_relative_iso(self):
function_cfg = {
Expand Down Expand Up @@ -159,6 +169,28 @@ def test_string_to_epoch(self):
expected = 1608854400
self.execute_function_test(function_cfg, expected)

@freeze_time("2021-01-01")
def test_strtotime_empty_base_time(self):
function_cfg = {
"function": "strtotime",
"args": [
"now"
]
}
expected = 1609459200
self.execute_function_test(function_cfg, expected)

@freeze_time("2021-01-01")
def test_strtotime_empty_base_time_before_days(self):
function_cfg = {
"function": "strtotime",
"args": [
"-2 days"
]
}
expected = 1609286400
self.execute_function_test(function_cfg, expected)

def test_concat_ws(self):
function_cfg = {
"function": "implode",
Expand Down

0 comments on commit a1c8ccd

Please sign in to comment.