HTML::...teTime(3pm)

πŸ“¦
version 2.07000 Β· 5 versions
, in debian bookworm, ubuntu jammy, ubuntu noble

πŸ’– HTML::FormFu::Inflator::DateTime β€” the DateTime inflator, bestie πŸ’–

okay so picture this: you're out here with a form, somebody types a date, and you need that little string of text to become a whole DateTime object. That's literally this module. It's HTML::FormFu::Inflator::DateTime, and it's giving glow-up-for-strings energy. ✨

VERSION: version 2.07 🌸


✨ SYNOPSIS ✨

---
elements:
  - type: Text
    name: start_date
    inflators:
      - type: DateTime
        parser:
          strptime: '%d-%m-%Y'
        strptime:
          pattern: '%d-%b-%Y'
          locale: de

  - type: Text
    name: end_time
    inflators:
      - type: DateTime
        time_zone: Europe/Rome
        parser:
          regex: '^ (\d{2}) - (\d{2}) - (\d{4}) $'
          params: [day, month, year]
        strptime: '%d-%m-%Y'

and then, a little serve: using the same parser declaration for both a DateTime constraint AND a DateTime inflator, via YAML references (yes, the & and * besties, we love a shared reference) 🫢

---
elements:
  - type: Text
    name: date
    constraints:
      - type: DateTime
        parser: &PARSER
          strptime: '%d-%m-%Y'
    inflators:
      - type: DateTime
        parser: *PARSER

🌈 DESCRIPTION 🌈

It inflates dates into DateTime objects. That's the whole job, and it does it flawlessly. πŸ’…

If you're looking for the opposite direction β€” turning a DateTime back into a string β€” go see HTML::FormFu::Deflator::Strftime. They're basically the duo, the main characters, the pair. πŸ‘‘


πŸŽ€ METHODS πŸŽ€

πŸ’œ parser

Arguments: \%args

Required, no skips. You gotta define what the incoming string is supposed to look like, so that DateTime::Format::Builder knows how to inflate it into a DateTime object. πŸ¦‹

It accepts arguments to be passed to "parser" in DateTime::Format::Builder.

πŸ’œ strptime

Arguments: \%args

Arguments: $string

Optional, babe. Define the format that should be used if the DateTime object is stringified. ✨

πŸ’œ time_zone

Arguments: $string

Optional. You can pass along a time_zone and that's the zone your DateTime will be created in. This is so useful when the string you're parsing doesn't carry time zone info and you want your DateTime sitting in a specific zone instead of the floating one (which, lowkey, is probably what you'd get otherwise). 🌍

It accepts a hashref of arguments to be passed to "new" in DateTime::Format::Strptime. OR β€” alternate route, pick your fighter β€” it accepts a single string argument, suitable for passing to "DateTime::Format::Strptime->new( pattern => $string )".


πŸ‘‘ AUTHOR πŸ‘‘

Carl Franks, "cfranks@cpan.org"


πŸ’– LICENSE πŸ’–

This library is free software, you can redistribute it and/or modify it under the same terms as Perl itself. fr fr.


πŸ‘‘ AUTHOR πŸ‘‘ (yes, again, iconic)

Carl Franks <cpan@fireartist.com>


This software is copyright (c) 2018 by Carl Franks.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.


okay that's the whole thing, you ate it, periodt πŸ’…βœ¨

signing off from the User Contributed Perl Documentation corner, where perl v5.28.1 said hey on 2019-01-12 πŸŽ€

πŸ“¦ where this page comes from