Closed AndreasBackx closed 5 years ago
As of the next version (likely 0.8.0
), both create_from_date()
and create_from_time()
will be deprecated since you can use create()
to get the same behavior.
Regarding with_date()
and with_time()
they will be replaced by on()
and at()
(with a deprecation warning) to avoid the confusion and the intuitive will to pass date
and time
objects to them.
So, in the end, I do not intend to support passing native objects to them in a near future.
Unfortunate, it's quite annoying to write:
some_pendulum.on(
year=some_date.year,
month=some_date.month,
day=some_date.day
)
It would just be neat if we could write:
some_pendulum.on(some_date)
We could always just use simple *args
and **kwargs
manipulation to make that possible? Am I missing something behind why you don't intend on supporting it? It seems to be a lot more intuitive.
For dates you can:
import datetime, pendulum
today_datetime = datetime.date.today()
pendulum.create(*today_datetime.timetuple()[:3])
@danilobellini that's neat, but still a bit of a workaround and not as clean imo.
@AndreasBackx For now, I don't want to change the API any further. I will rename and remove these methods but won't change their signatures.
It's not set in stone and I might introduce it at some point since I agree that it could help a little but I just don't want to make a lot of changes on the road to the first stable 1.0.0
version.
I will even make a 0.8.0
that I hadn't planned to give people time to adjust.
I will keep this idea in mind though but just don't expect it to make it to the 1.0.0
version :-)
@sdispater unfortunate, I hoped that it could've been added before 1.0.0 because it remains backwards compatibility. Too bad then.
@sdispater Isn't this right up the alley of pendulum.instance()
? Right now this throws an AttributeError
because of course datetime.date
doesn't have a tzinfo
attribute, but patching up instance()
to support date
and time
instances rather than just datetime
would be trivial and seemingly backwards-compatible. Actually, it appears the only reasons one can't already use this is because pendulum.py#198 is unsafe and uses dt.tzinfo
without a hasattr
safety check, and the fact that lines 211-215 also blindly assume a full datetime instance (getattr
's 3rd argument could be handy in a refactor here).
I don't think I will change instance()
to accept date
and time
objects. This is what Date.instance()
and Time.instance()
are for.
The initial and only purpose of instance()
is to transform a datetime
object to a Pendulum
object.
And as I said, it's fairly easy to get a Pendulum
instance from a date
or even a time
.
Regarding on()
and at()
methods, I haven't made my mind yet. That's why I am leaving this issue open for now.
Currently the Pendulum supports creating from given hours, minutes... using:
Pendulum.create_from_date
Pendulum.create_from_time
Pendulum.with_date
Pendulum.with_time
These all however require you to pass the hours, minutes and more manually. It would be great if these accepted the
datetime.date
anddatetime.time
classes like so:Many libraries incorporate these classes and transforming them using Pendulum would be great.