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
[ The reason inside ] DateTime\DateTimeImmutable\DateTimeInterface.... how much more? #7965
Comments
Could you try summarizing what it is that you're asking for? |
Fix date syntax, cus of there's no 1 problem. There's 12 problems in a row, that is created everytime this lib was upgraded. Its good features but really to work with dates you have to write private method for 30 lines in each file. Cause of broken syntax. |
This issue tracker is for bug reports and feature requests. If you'd like to talk about how difficult it has been for you to use DateTime and DateTimeZone then consider signing up with WordPress or Blogger. If you'd like help understanding how to use them better then try asking on StackOverflow or elsewhere. If you don't want to deal with PHP's date/time classes yourself then there are libraries like Carbon you can use instead. If you have concrete suggestions for what PHP could do differently then check out the RFC process. |
"Nice work bitch" (c) Escape From Tarkov Three times i've catched PHP Dev Team realises idea that i proposed 3 years before. So slow. Ignore, ban, block, shoot. (c) Earth Continue to listen these "webinars" about whats better postgres or mysql. |
@6562680 They might be slow to implement some features, but they also are responsible for stability and integrity of this project, so even if sometimes frustrating, they have right to make own choices. You're report is chaotic and hostile, nobody wants to read that. And your bad experiences does not justify being d.. to random maintainers. If you want real change, be constructive and respectful. |
Respectfullness will not lead you do success. In any cases. 1 way) In market cases only respectless gives you money - ppl likes those who do forbidden things, not them who has emathy (jesus was murdered, yes?) - and ITS NOT my way (if yours - the speak is end right now) 2 way) In science cases respectfullness is only emotion, emotion needed by your brain, not by society. Emotion - is an engine being inside you, gives you energy. Its not bad, its required thing, very powerfull thing, but emotions should GIVE energy instead of CONTROL your action. When you prefer emotions while working with society - you'll get the war about preferences, holywar i mean, and after some time - no results, spent time and its all. Society is about "we have to take care about this bastards otherwise they destroy each one, and us too in the batch". They dont need your help or salvation. They will scold and even resist you. Its not about "they dont want". Its about "they dont know what they want". But if you dont participate - powerfuls of this world ask you to "defend the motherland" and gives you rifle to kill another guys who dont want the war like you. It will work like that: Correct way is "apologize, ask, listen, understand, imagine solution, present it, spent some time to talk about". There's not respectfulness. This story is about "what happens if?" and "what it looks like?" This way is not available for 95% of ppl. For the justice 15 years ago this way wasnt available for 85% ppl. Today - 95%. More poor people - less respectful people. War moves closer. Be safe. |
I answer with a quote that you didnt even read, but already ask me to go away:
Remember. We didnt write workers 90% of the time. Our scripts initialises 1000 times in a seconds in parallel with nginx. |
He's crazy but he's right (c) |
Description
\DateTime, \DateTimezone, \DateInterval marked with \Exception. Most used editor PHPStorm highlights it. Since it is very internal method - using native \DateTime forces highlight all the code. Highlighting means "PLEASE TRY CATCH IT". So since 50% percent of tasks needs dates inside their logic - you have try/catch in 50% code just to hide damn exception and throw \Runtime instead. Its still an exception. But hidden one. So we have guys who wants ClockInterface
Next one - Relative Date vs Absolute date. In PHP we have the date as single feature (but with 3? or more implementations) - functional way, object way, etc. The point is TIMEZONE. I dont know how exactly initial timezone comes inside PHP (while no one in config - perhaps at build from source time) - but i saw 10+ servers where unix commands show that the timezone is UTC, but PHP shows timezone as "Helsinki" or something. Yes it could be fixed with
php.ini
.But with next things:
(1) You still have timezone in your database that could be different from your Unix. And with your php. And you WILL dance with that +1 -2 +3 -4 every time. Best configuration - same timezone everywhere. To do that you should be at least amateur in linux/docker/(mysql|postgres)/php+fpm. Usually this amateur is a guy known as dev-ops, he is clever guy, he wants 3000 USD/month to work only 10minutes per month in case your app falls down. Most product companies prefers outsourcing, and now you CANT ask this guy about this timezone without democratic negotiations.
(2) You know about timezone difference in maybe 2-3 months after project published. It already has a database for maybe 100k-1m records minimum with failed dates. And now you get the task "i dont know, but we differ in 2 hours, please, be THE PROGRAMMER - solve our brainpain"
The reason of above is IMPORTANT difference between relative and absolute date.
Relative date comes from your CPU clock. You write "today" or "yesterday" and you'll get for me (now):
2022-01-18 20:00:00 UTC+2
Ok, lets remember your server (and your postgres configured with UTC). You apply
new \DateTimeZone('UTC')
one of this way:You ALWAYS get unexpected difference in (for me) 2 hours. So the time will be:
2022-01-18 18:00:00 UTC+0
But wait, now you should do that in your brain on every math operation, and try to remember it.
How to get same date as you see in your mac/windows/ubuntu tray, huh, developer?
Tada (it isnt "correct", its "usable", btw humans always incorrect):
How many hours newbie should spent to research that ?? The point is difference between RELATIVE and ABSOLUTE dates. If you pass timezone as 2nd parameter with relative date - it will be applied like "create date, then - change timezone", instead of "create MY date in described timezone", do you get that?
BUT, we want to apologize - "today midnight" isnt a RELATIVE date. Actually not fully relative. It creates the date with 00:00:00 timestamp. And it will surprise you only if date been created inside UTC difference (for me) 2 hours from UTC. There will be previous day, but server awaits next one.
How about create DIFFERENT classes for Relative date and Absolute date?
Postgres solves that by presenting two different types \DateTime + \DateTimeWithTimezone. Problem of that - you cant just add timezone for non-timezone date, so postgres wont solve that
Or fix the behavior - "today, UTC" means "GET MY TIME IN UTC, I KNOW ITS A MISTAKE, BUT IT WILL HELP ME" :DD
And the next point.
When we serialize date into some storage, we need DATE_ATOM or maybe sql date format.
But while we're in the code - we need objects.
So creating date with
new \DateTime()
(and actually twice, and actually with timezone, and actually with trycatch in each class) - it wont respects use case "we already have the date object" so we need everywhere write that damninstanceof
stuff:Lets rewrite:
To create date in PHP safely you need to always write that construct. In each class you need dates.
And am not speaking about
humanize date
stuff,localize today/yesterday/tomorrow
,localize ago dates
(ohh, you WILL meet the \IntlFormatter fromlib-intl
, and spent 3-4 hrs to remember it for long (?), am sure), and actually wont speak aboutlocalize ago in human expected format
- that means "less than day = minutes/hours ago, greater than day - show date in Ymd" like Pavel Durov does.Lets fix at least relative date stuff. Just to reduce syntax.
Other stuff we could speak later.
Thanks for your time, folks. Be safe.
[ Гриша, ты уже всех достал своим английским, уходи ]
The text was updated successfully, but these errors were encountered: