PSR-20 Clocks: Testable Time in PHP
– doeken.org - submitted by Doeke Norg
Learn how a ClockInterface helps you decouple time and write stable, testable code. It's about time!
Read more [doeken.org]
Posts tagged with datetime
– doeken.org - submitted by Doeke Norg
Learn how a ClockInterface helps you decouple time and write stable, testable code. It's about time!
Read more [doeken.org]
– gdebrauwer.dev - submitted by Günther Debrauwer
In your Livewire components, you might want to display dates in the browser's timezone. In this post, I explore how you could achieve this.
Read more [gdebrauwer.dev]
Join 9,500+ smart developers
Every month I share what I learn from running Spatie, building Oh Dear, and maintaining 300+ open source packages. Practical takes on Laravel, PHP, and AI that you can actually use.
No spam. Unsubscribe anytime. You can also follow me on X.
Michael Dyrynda explains how you can use immutable dates in Laravel by default.
Read more [dyrynda.com.au]
When a site is down, Oh Dear sends a notification every hour. Since last year, our notifications can be snoozed for a fixed amount of time (5 minutes, 1 hour, 4 hours, one day).
In the evenings and weekends, our users might not want to receive repeated notifications. That's why we've added a nice human touch: all notifications can now be snoozed until the start of the next workday.
In this blog post, I'd like to share some of the code that powers this feature. We'll focus on how the start of the next workday is calculated.
Maggie Johnson-Pint discusses where the JavaScript Date goes bad, better ways to model the date and time space in our code, and how the Temporal proposal making its way through TC39 helps us write correct code for every person in every time zone.
?♂️⏲️ Just found all these handy class constants in Carbon - woohoo! ? pic.twitter.com/pL0HeKGVx4
— Caleb Porzio (@calebporzio) 29 juni 2018
Read more [twitter.com]
⏲️ Handy eloquent macro for the date comparison impaired ? pic.twitter.com/rUgLlEywrn
— Caleb Porzio (@calebporzio) April 25, 2018
Read more [twitter.com]
Jeff Madsen wrote down a good piece that explains how mutable Carbon dates can lead to some nasty bugs. I would't mind if Chronos were to be promoted to the default datetime library in Laravel.
If you hang out on any sort of programming forums you have no doubt encountered “The Great Mutable vs. Immutable Debate”. While I’m sure you know what the words mean, if you are new to programming or don’t have a strong Computer Science background it might not be obvious to you whether this is an important concept to be concerned with, or just more “architecture astronaut” purists arguing some obscure fine point.To help you answer that for yourselves, I’m going to show you the difference between the two using two popular Php DateTime libraries — Carbon and Chronos, and then demonstrate the danger of using the mutable one of those.
https://medium.com/@codebyjeff/whats-all-this-immutable-date-stuff-anyway-72d4130af8ce
If you want to read more cool articles by Jeff, be sure to subscribe to his excellent newsletter.
Ross Tuck is probably one of my favourite bloggers. He doesn't publish something often (his previous post is from 2015), but when he does it's very much worth your time.
The important takeaway here isn’t “value objects, yay, inline juggling, boo!” It’s that we were able to remove several classes of errors by reducing the precision of the DateTime we were handling. If we hadn’t done that, the value object would still be handling all of these edges cases and probably failing at some of them too.Reducing the quality of data to get a correct answer might seem counter-intuitive but it’s actually a more realistic view of the system we’re trying to model. Our computers might run in picoseconds but our business (probably) doesn’t. Plus, the computer is probably lying anyways.
http://rosstuck.com/precision-through-imprecision-improving-time-objects
Q: What does this code return?
date('Y-m-d',strtotime('00-00-00'));
A: 1999-11-30
B: 0001-01-01
C: 2001-01-01
The correct answer is A: 1999-11-30.
You'll find the reasoning behind this result as a comment on this bug report.
There is no bug here, 00-00-00 means 2000-00-00, which is 1999-12-00, which is 1999-11-30. No bug, perfectly normal.