Jerod Santo: There are plenty of times in my career when I’ve stored a boolean and later wished I’d had a timestamp. There are zero times when I’ve stored a timestamp and regretted that decision. Hear hear! Over the years I’ve come to include 9 meta fields for most of the tables I create: added_at, …
Tag Archives: datetime
JavaScript Temporal API — A Fix for the Date API
Anyone who has worked with dates and time in JavaScript knows how broken the built-in Date is. In the near future we’ll be able to use Temporal instead, an ECMAScript feature currently at Stage-3 Nathan Sebhastian has a good overview on how it compares to Date, along with some practical examples. The new Temporal API …
Continue reading “JavaScript Temporal API — A Fix for the Date API”
Formatting a Date
in JavaScript with Intl.DateTimeFormat
Phil Nash walks us through using Intl.DateTimeFormat to format a Date to a specific timezone and format. const shortcutFormatter = Intl.DateTimeFormat("en-AU", { timeZone: "Australia/Melbourne", timeStyle: "long", dateStyle: "short" }); shortcutFormatter.format(date); // => "22/2/21, 5:05:52 pm AEDT" How to display dates in your user’s time zone with the Intl API → Related: Think you know a …
Continue reading “Formatting a Date
in JavaScript with Intl.DateTimeFormat
“
PHP: Convert a Geolocation (Latitude / Longitude Coordinates) to a Timezone identifier
Part of a PHP project I’m working contains a list of sites/buildings. For each site/building we monitor some data, for example its energy usage. We decided that we wanted to generate a daily/weekly/monthly reports of the data, by aggregating the datapoints. As our sites/buildings are spread across the globe – and thus timezones – we …
Why Denmark Is .17 Seconds Behind The World
How to Perform Calendar Calculations in Your Head
In case you want to impress your family over Christmas’/New Year’s Dinner: A so-called calendrical savant (or calendar savant) is someone who despite their intellectual disability (typically autism) can name the day of the week of a given date, or visa versa in a few seconds or even a tenth of a second (Kennedy & …
Continue reading “How to Perform Calendar Calculations in Your Head”
spatie/test-time
– A PHP package to control the flow of time
Freek has created spatie/test-time, a package to easily freeze/rewind/advance time in PHP. Imagine you’re building that your app can notify your user, but you don’t want to send more than one notification in a timeframe of five seconds. How are you going to test the time aspect? Do you have to create a test that …
Continue reading “spatie/test-time
– A PHP package to control the flow of time”
Symfony Form Validation: Validating a date range
One of the (Symfony based) PHP projects I’m working on contains a form which allows the user to generate video clips from CCTV footage. To do this the user can enter a start and stop DateTime. For this to work the submitted input data is then checked: both start and stop must be dates, and …
Continue reading “Symfony Form Validation: Validating a date range”
php-timecop
– A PHP extension providing “time travel” capabilities
Now this looks handy, especially when you’re writing/testing code that’s dependent on the system’s time: php-timecop is a PHP extension providing “time travel” and “time freezing” capabilities Freeze time to a specific point. Travel back to a specific point in time, but allow time to continue moving forward from there. Scale time by a given …
Continue reading “php-timecop
– A PHP extension providing “time travel” capabilities”
Carbon – A simple PHP API extension for DateTime.
$carbon = new Carbon(‘first day of next week’); if ($carbon->isWeekend()) { echo ‘Party!’; } echo $carbon->addYear()->diffForHumans(); // ‘in 1 year’ Carbon is just a class which is designed to be used instead of DateTime. Due to extending DateTime, all DateTime methods are available to users of Carbon. Additionally, it implements a __toString method, allowing users …
Continue reading “Carbon – A simple PHP API extension for DateTime.”