Skip to content

Relax date format requierment (UTC) #91

Description

@blogh

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.

Activity

  1. dlax commented on Oct 18, 2021

    @dlax
    Contributor

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

  2. blogh commented on Dec 7, 2021

    @blogh
    Author

    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)
    
  3. dlax commented on Dec 14, 2021

    @dlax
    Contributor

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions