NAME

autobox::Time::Piece - on-the-fly date conversion

SYNOPSIS

use autobox::Time::Piece;

my $date = '2025-07-12';
my $tp   = $date->strptime('%Y-%m-%d');
my $str  = $tp->format('%A, %B %d, %Y');

my $converted = $date->convert('%Y-%m-%d', '%d/%m/%Y');

DESCRIPTION

This module extends scalars, arrays, and hashes with methods from Time::Piece. It allows strings and other data to behave like date objects through autoboxing.

METHODS

All methods are injected into SCALAR, ARRAY, and HASH types.

SCALAR->strptime($format)

Parses the string into a Time::Piece object using the given strftime-style format. If no format is given, it falls back to localtime(). If the scalar is already a Time::Piece object, it is returned unchanged.

SCALAR->parse($format)

Alias for "strptime".

SCALAR->format($format)

Formats a Time::Piece object or a parseable string using the given format string. Alias for "strftime".

SCALAR->convert($from_format, $to_format)

Parses the string using $from_format and re-serializes it using $to_format.

AUTOLOAD

Any method called on a scalar (or other supported type) that matches a method in Time::Piece will be dynamically delegated to it. For example:

my $day_of_year = '2025-07-12'->strptime('%Y-%m-%d')->yday;

# or directly:
my $dow = '2025-07-12'->wdayname;

This mechanism ensures that common Time::Piece methods like year, mon, yday, etc. are accessible without manual conversion.

SEE ALSO

autobox, Time::Piece, Time::Piece::strptime

AUTHOR

Simone Cesano

This software is copyright (c) 2025 by Simone Cesano.

COPYRIGHT AND LICENSE

This software is copyright (c) 2025 by Simone Cesano.

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