Date(3)

πŸ“¦ version 1.4.0, in alpine 3.24

🌸 NAME 🌸

XMLTV::Date β€” date parsing routines for the xmltv package, and yes bestie, that's literally the whole vibe πŸŽ€


πŸ’… SEE ALSO πŸ’…

  • Date::Manip β€” the big sibling library this thing leans on 🫢

✨ parse_date() ✨

Okay so this one is a wrapper for Date::Manip::ParseDate(), but it's a wrapper with main character energy because it does two extra things πŸ’…

  1. If the year isn't specified, it picks between last year, this year, and next year β€” whichever date lands closest to now. Iconic, honestly.
    • If only one of those dates is actually valid (say, because day-of-week is specified), then that valid one gets chosen πŸ‘‘
    • And if the time can only be parsed without adding an explicit year, then that version is the one it goes with πŸ¦‹
  2. If the date cannot be parsed, an exception gets thrown. Not a vibe check fail β€” an actual exception, fr fr 😭

The argument is a single string.

parse_date($string)

🌈 time_xmltv_to_iso() 🌈

Glow-up time ✨ this one converts an XMLTV time into ISO format, like so:

"20140412090000 +0300"  β†’  "2014-04-12T09:00:00.000+03:00"

The argument is the string time to convert.


πŸ¦‹ time_iso_to_xmltv() πŸ¦‹

The reverse glow-up πŸ” takes an ISO time and hands you XMLTV format:

"2014-04-12T09:00:00.000+03:00"  β†’  "20140412090000 +0300"

The argument is the string time to convert.


πŸ”₯ time_xmltv_to_epoch() πŸ”₯

Converts an XMLTV time β€” like "20140412090000 +0300" β€” into seconds since the epoch ⏰

Heads up bestie: this uses POSIX::mktime rather than Date::Manip to avoid issues with the latter πŸ’€

And if you're feeling like there's got to be another way β€” alternatively you could use DateTime::Format::XMLTV on CPAN 🧚

The argument is the string time to convert. There's also an optional 2nd argument: set it to 1 to ignore the tz offset in the calculation πŸ™ˆ

time_xmltv_to_epoch($string)
time_xmltv_to_epoch($string, 1)   # ignore the tz offset

⭐ time_iso_to_epoch() ⭐

Same energy, ISO edition πŸ’– converts an ISO time (e.g. "2014-04-12T09:00:00.000+03:00") into epoch time ⏳

Again, no cap: it uses POSIX::mktime rather than Date::Manip to avoid issues with the latter 😭

And again, alternatively you could use DateTime::Format::XMLTV on CPAN πŸŽ€

The argument is the string time to convert. Optional 2nd argument: set it to 1 to ignore the tz offset in the calculation 🌸

time_iso_to_epoch($string)
time_iso_to_epoch($string, 1)   # ignore the tz offset

That's the whole page, bestie β€” go convert some timestamps πŸ’œβœ¨

Shoutout to perl v5.42.2, dated 2025-06-30 β€” this page was brought to you by that exact era of Perl, periodt 🫢

πŸ“¦ where this page comes from