aboutsummaryrefslogtreecommitdiffhomepage
path: root/misc/format_datetime.php
diff options
context:
space:
mode:
authorwinter2025-02-07 18:26:05 +0000
committerwinter2025-02-07 18:26:05 +0000
commitd18ec187847893f94418b29bc6a087d6b2dd9a2d (patch)
tree8ea4451cb1f62f8041eae71ca60ec2b64fafe8b2 /misc/format_datetime.php
parent43f0b9f41a582925838b2ba686110b2f07576be3 (diff)
localise note timestamps and stuff
Diffstat (limited to 'misc/format_datetime.php')
-rw-r--r--misc/format_datetime.php14
1 files changed, 14 insertions, 0 deletions
diff --git a/misc/format_datetime.php b/misc/format_datetime.php
new file mode 100644
index 0000000..1a4db52
--- /dev/null
+++ b/misc/format_datetime.php
@@ -0,0 +1,14 @@
+<?php
+
+function format_datetime(
+ DateTimeInterface $dt,
+ DateTimeZone|IntlTimeZone|string|null $tz = null
+): string {
+ static $formatter = new IntlDateFormatter(
+ get_ui_language(),
+ IntlDateFormatter::RELATIVE_MEDIUM,
+ IntlDateFormatter::SHORT
+ );
+ $formatter->setTimeZone($tz ?? $dt->getTimezone());
+ return $formatter->format($dt);
+} \ No newline at end of file