Date(3pm)

πŸ“¦
version 1.4.0 Β· 4 versions
, in debian trixie, ubuntu resolute, ubuntu stonking

πŸ’– NAME πŸ’–

okay bestie, gather round, because this is XMLTV::Date β€” date parsing routines for the xmltv package ✨ It's a Perl module (that's the 3pm situation, iykyk), and it is so handy if you're out here wrangling dates from XMLTV files and you're tired of crying about it.


πŸ‘€ SEE ALSO πŸ‘€

  • Date::Manip β€” the icon this whole thing is built on top of 🫢

πŸ’… parse_date() πŸ’…

This one is a wrapper for Date::Manip::ParseDate() that does two extra things, and honestly? iconic behaviour.

  1. if the year is not specified, it picks between last year, this year and next year based on which date would be closest to now. and like, if only one of those dates is valid β€” say because day-of-week is specified β€” then the valid one gets chosen, no drama. and if the time can only be parsed without adding an explicit year, then that's the one it goes with. it just knows. πŸ’«
  2. an exception is thrown if the date cannot be parsed. no silent fails, no weird vibes, it WILL let you know 😭

Argument is a single string. that's it, that's the whole ask.


🌸 time_xmltv_to_iso() 🌸

Converts a XMLTV time to ISO format, like a lil glow-up for your timestamps:

  • from: 20140412090000 +0300
  • to: 2014-04-12T09:00:00.000+03:00

Argument is string time to convert. slay.


πŸ¦‹ time_iso_to_xmltv() πŸ¦‹

the reverse glow-up, bestie. converts an ISO time to XMLTV format:

  • from: 2014-04-12T09:00:00.000+03:00
  • to: 20140412090000 +0300

Argument is string time to convert.


⭐ time_xmltv_to_epoch() ⭐

Converts a XMLTV time to seconds since the epoch:

  • from: 20140412090000 +0300
ngl this one uses POSIX::mktime rather than Date::Manip on purpose β€” to avoid issues with the latter. the drama was real, so we went around it πŸ’€

alternatively you could use DateTime::Format::XMLTV on CPAN, if that's more your vibe.

Argument is string time to convert. Optional 2nd argument: set to 1 to ignore the tz offset in the calculation. πŸ‘‘


πŸŽ€ time_iso_to_epoch() πŸŽ€

Converts an iso time to epoch time:

  • from: 2014-04-12T09:00:00.000+03:00
same energy as above: uses POSIX::mktime rather than Date::Manip to avoid issues with the latter 🫠

and again, alternatively you could use DateTime::Format::XMLTV on CPAN.

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


okay that's the whole page, you're officially educated 🧚 this was documented for perl v5.40.1, dated 2025-04-19 β€” go forth and parse some dates, bestie, you've got this πŸ’œπŸŒˆ

πŸ“¦ where this page comes from