utils icon indicating copy to clipboard operation
utils copied to clipboard

Immutable DateTime [WIP]

Open dg opened this issue 8 years ago • 13 comments

  • new feature? no
  • BC break? yes

I am looking for way how move from mutable to immutable DateTime.

From my point of view, mutable DateTime is something you never want (of couse I may be wrong). And switch from mutable to immutable is big BC break. On the other hand, I found way how to discover bottlenecks (like this one) where mutable and immutable behave differently and I can trigger error. So maybe the transition from one model to another would be possible.

dg avatar Feb 01 '17 15:02 dg

+1 for immutable version, but I don't think changing parent class is a good idea due to BC constraints, mostly because of typehints in userland and entirely different behavior... Rather properly deprecate DateTime in favor of new variant.

Majkl578 avatar Feb 01 '17 16:02 Majkl578

Deprecate for new variant seems better to me. The point is that a lot of people just will change class name, so functionality that traces bottlenecks should be useful in new class.

I am not sure about name, because Nette\Utils\DateTimeImmutable sounds terrible to me.

dg avatar Feb 01 '17 16:02 dg

I am not sure about name, because Nette\Utils\DateTimeImmutable sounds terrible.

Why? It sounds explicit and logic.

  • DateTime => Nette\Utils\DateTime
  • DateTimeImmutable => Nette\Utils\DateTimeImmutable

TomasVotruba avatar Feb 01 '17 16:02 TomasVotruba

\DateTimeImmutable sound terrible too :)

dg avatar Feb 01 '17 16:02 dg

Well, that's issue for another repository :)

TomasVotruba avatar Feb 01 '17 16:02 TomasVotruba

What about something like that Nette\Utils\Immutable\DateTime, that also wrong, but something like this principle

michalhlavka avatar Feb 01 '17 16:02 michalhlavka

There is still #82 though - kill DateTime entirely. 😊

Majkl578 avatar Feb 01 '17 16:02 Majkl578

To kill DateTime is colossal BC break.

dg avatar Feb 01 '17 16:02 dg

Migration to different class is as well and helper methods would be kept in new helper class. And honestly, what is the added value of extending (inheriting) PHP's DateTime(Immutable)? Adding some helper methods and making code less portable?

Majkl578 avatar Feb 01 '17 16:02 Majkl578

__toString and jsonEncode is added value.

(I dont need them, but BC…)

dg avatar Feb 01 '17 17:02 dg

Helper class for immutable DateTime factories can have name DateTimes, for cosistency with Arrays and Strings ;)

dg avatar Feb 01 '17 17:02 dg

What about name Timestamp?

milo avatar Feb 02 '17 17:02 milo

The helper class for the added functionality (working with DateTimeInterface) and just deprecating Nette DateTime is IMHO the best option.

The loss of __toString kinda sucks, but other aspects outweight the loss of it.

pavelkouril avatar Feb 13 '17 08:02 pavelkouril