DateTim...::Regex(3)

πŸ’… NAME πŸ’…

ok so this is DateTime::Format::Builder::Parser::Regex β€” it's the regex-based date parsing parser, bestie. That's the whole vibe: you give it a regex, it gives you dates ✨


πŸŽ€ VERSION πŸŽ€

version 0.83 β€” yes that's the number, write it down 🫢


πŸ¦‹ SYNOPSIS πŸ¦‹

like, here's the moment you've been waiting for:

my $parser = DateTime::Format::Builder->create_parser(
    regex  => qr/^(\d\d\d\d)(\d\d)(\d\d)T(\d\d)(\d\d)(\d\d)$/,
    params => [qw( year month day hour minute second )],
);

no cap, that's it. that's the whole thing πŸ’–


🌸 SPECIFICATION 🌸

so beyond the common keys (iykyk), Regex also supports these bad boys:

  • regex β€” this is a regular expression that should capture elements of the datetime string. it's a required element, periodt. this is also the key whose presence is what tells everyone "hey, this spec belongs to this class" πŸ‘‘
  • params β€” an arrayref of key names. the captures from the regex get mapped onto these ($1 goes to the first element, $2 to the second, and so on and so forth) and then handed off to DateTime->new. also required, no skipping πŸ™ˆ
  • extra β€” a hashref of extra arguments you wanna hand to DateTime->new. like, you could set the year or time_zone to defaults:
extra => { year => 2004, time_zone => "Australia/Sydney" },

iconic little defaults moment πŸ’œ

  • constructor is either an arrayref or a coderef. if it's an arrayref, then the first element is a class name or object, and the second element is a method name (or a coderef, since Perl literally allows that sort of thing 🫠). the arguments to the call are anything in $p plus anything you gave in the extra option up above.

if you only supply a coderef, then it gets called with arguments of $self, $p and extra.

in short, bestie:

$self->$coderef( %{$p}, %{ $self->{extra} } );

the method is expected to return a valid DateTime object, or undef if it fails 😭 β€” but it can conceivably return anything it likes. so long as it's 'true', we're chilling ✨


🌈 SEE ALSO 🌈


🧚 SUPPORT 🧚

bugs may be submitted at <https://github.com/houseabsolute/DateTime-Format-Builder/issues> β€” go off, report that bug πŸ›

I'm also usually active on IRC as 'autarch' on "irc://irc.perl.org" πŸ‘‘ come say hi fr fr


⭐ SOURCE ⭐

the source code repository for DateTime-Format-Builder can be found at <https://github.com/houseabsolute/DateTime-Format-Builder> β€” go look, it's giving open source excellence πŸ’…


πŸ‘‘ AUTHORS πŸ‘‘

  • Dave Rolsky <autarch@urth.org>
  • Iain Truskett <spoon@cpan.org>

legends, both of them 🫢


this software is Copyright (c) 2020 by Dave Rolsky.

this is free software, licensed under:

The Artistic License 2.0 (GPL Compatible)

the full text of the license can be found in the LICENSE file included with this distribution πŸ“„ read it, it's good for you πŸ“


okay that's the whole page, mwah πŸ’‹ β€” sign-off time: this was perl v5.40.0, dated 2023-01-15, and yes it's still DateTime::Format::Builder::Parser::Regex(3) in case you forgot already πŸ˜­πŸ’œ

πŸ“¦ where this page comes from