Skip to content

Initialize from existing datetime.date object? #250

Closed

Description

@jacebrowning

pendulum.instance(dt) works for datetime.datetime, but how can I initialize a Pendulum object from an existing datetime.date (specifically a Django DateField)?


My current workaround:

pendulum.parse(str(date_object))

Activity

  1. jacebrowning commented on Jul 21, 2018

    @jacebrowning
    ContributorAuthor

    Could we add that behavior to pendulum.instance()?

  2. kakulukia commented on Aug 31, 2018

    @kakulukia

    +1

  3. trancee commented on Sep 4, 2018

    @trancee

    +1

    I would also check for datetime.time so we have all possible cases of a datetime covered with Pendulum.

  4. joaodlf commented on Dec 12, 2018

    @joaodlf

    +1 This would be a great addition to the API!

  5. SemMulder commented on May 6, 2019

    @SemMulder

    +1

  6. joaomcarlos commented on Sep 27, 2019

    @joaomcarlos

    +1

  7. racerthunder commented on Mar 17, 2020

    @racerthunder

    +1

  8. lonsun commented on Jun 26, 2020

    @lonsun

    +1

  9. Alsanis commented on Jul 6, 2020

    @Alsanis

    +1

  10. rodrigondec commented on Sep 16, 2020

    @rodrigondec

    +1

  11. madisvain commented on Apr 27, 2021

    @madisvain

    I would like to pump this. I find doing this over and over and would love if pendulum had this feature built in.

  12. AaronBeaudoin commented on Nov 16, 2021

    @AaronBeaudoin

    This is a no-brainer for me. I work with an ORM that returns datetime.date instances, and having to pick them apart to pass them into pendulum.instance feels like the symptom of a missing feature.

  13. richieadler commented on Jan 28, 2022

    @richieadler

    +1

  14. kakulukia commented on Mar 1, 2022

    @kakulukia

    I have created a first draft at https://github.com/kakulukia/pendulum .. im missing some tests before opening a puss request, but like to get some feedback first.

  15. blondelg commented on Dec 30, 2022

    @blondelg

    +1

  16. yardensachs commented on May 3, 2023

    @yardensachs

    +1

  17. lena commented on May 3, 2023

    @lena

    +1

  18. mcguigon0033 commented on May 3, 2023

    @mcguigon0033

    +1

  19. jackb2113 commented on May 3, 2023

    @jackb2113

    +1

  20. codytowstik commented on May 8, 2023

    @codytowstik

    +1 !

  21. FichteFoll commented on Jul 3, 2023

    @FichteFoll

    I've also looked into the documentation & the code in search for this behavior. In the code, I see that even the shorthand class functions to initialize a Date like today first construct a native datetime.date object before they create the instance using its result. This surely would also profit from a Date.instance class function constructor.

    https://github.com/sdispater/pendulum/blob/c4e518c950bcf0a4214b36c5992ae27d3c40e47f/pendulum/date.py#L740-L755

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