Skip to content
This repository has been archived by the owner on Sep 23, 2024. It is now read-only.

Fix output format of time fields #187

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

edgarrmondragon
Copy link

@edgarrmondragon edgarrmondragon commented Aug 7, 2024

Context

Values like 8:30:00 fail validation against a {"type": "string", "format": "time"} schema, because they're not compliant with the specification.

Problem

Values of time fields are coming through as 8:30:00, for example. This is because the code incorrectly assumes the timedelta object will be stringified to HH:MM:SS:

elif isinstance(elem, datetime.timedelta):
if property_format == 'time':
row_to_persist += (str(elem),) # this should convert time column into 'HH:MM:SS' formatted string

One quick example, shows this is not the case

>>> import datetime
>>> str(datetime.timedelta(hours=8, minutes=30))
'8:30:00'

Proposed changes

We need to make fields with "format": "time" consistent with RFC 3339, section 5.6. So changing the code to

_total_seconds = int(elem.total_seconds())
_hours, _remainder = divmod(_total_seconds, 3600)
_minutes, _seconds = divmod(_remainder, 60)
row_to_persist += (f"{_hours:02}:{_minutes:02}:{_seconds:02}",) # this should convert time column into 'HH:MM:SS' formatted string

Types of changes

What types of changes does your code introduce to PipelineWise?
Put an x in the boxes that apply

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation Update (if none of the other choices apply)

Checklist

  • Description above provides context of the change
  • I have added tests that prove my fix is effective or that my feature works
  • Unit tests for changes (not needed for documentation changes)
  • CI checks pass with my changes
  • Bumping version in setup.py is an individual PR and not mixed with feature or bugfix PRs
  • Commit message/PR title starts with [AP-NNNN] (if applicable. AP-NNNN = JIRA ID)
  • Branch name starts with AP-NNN (if applicable. AP-NNN = JIRA ID)
  • Commits follow "How to write a good git commit message"
  • Relevant documentation is updated including usage instructions

@edgarrmondragon edgarrmondragon marked this pull request as ready for review August 7, 2024 02:30
@edgarrmondragon edgarrmondragon requested a review from a team as a code owner August 7, 2024 02:30
@edgarrmondragon
Copy link
Author

The unit test I added passes locally, along with all other unit tests. Let me know if there's anything else I can do to help this get merged.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant