Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Relax date format requierment (UTC) #91

Open
blogh opened this issue Oct 18, 2021 · 3 comments
Open

Relax date format requierment (UTC) #91

blogh opened this issue Oct 18, 2021 · 3 comments

Comments

@blogh
Copy link

blogh commented Oct 18, 2021

Hi,

raise ValueError("%s not in UTC." % raw)

Would it be possible to have an option to bypass this requirement ?
I wanted to use this class to handle log parsing in a project where I just needed the date "as is" and couldn't because of this.

@dlax
Copy link
Member

dlax commented Oct 18, 2021

Looks reasonable.
By the way, it's not clear to me why datetime.strptime() is not used directly here.

@blogh
Copy link
Author

blogh commented Dec 7, 2021

By the way, it's not clear to me why datetime.strptime() is not used directly here.

maybe it's because there are several formats in log_line_prefix ?

https://www.postgresql.org/docs/14/runtime-config-logging.html#GUC-LOG-LINE-PREFIX

  # %m (Time stamp with milliseconds)+ log_timezone = Europe/Paris
>>d = datetime.datetime.strptime("2021-09-22 19:00:45.894 CET", "%Y-%m-%d %H:%M:%S.%f %Z")
  
  # %t (Time stamp without milliseconds)
>>d = datetime.datetime.strptime("2021-12-07 10:14:04 CET", "%Y-%m-%d %H:%M:%S %Z")

--# %n (Time stamp with milliseconds (as a Unix epoch)) (not supported in pgtoolkit, never seen it, do we want it ?)
>>d = datetime.datetime.fromtimestamp(1638868691.099)

@dlax
Copy link
Member

dlax commented Dec 14, 2021

We could try different parsing methods (strptime, or even datetime.fromisoformat() when there is no tz info). Another option would be to use https://dateutil.readthedocs.io/en/stable/ but that would pull a dependency (the first, IIRC).

@blogh, if you need something to be changed in some way, feel free to submit a patch.

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

No branches or pull requests

2 participants