Module:...DateTime(3)
π NAME π
okay bestie, welcome to the Module::Generic::DateTime(3) page from the User Contributed Perl Documentation β¨ This is Module::Generic::DateTime β a DateTime wrapper with enhanced features, and she's literally serving convenience π
β¨ SYNOPSIS β¨
Here's the whole vibe in code, exactly as written π«Ά
use Module::Generic::DateTime;
my $dt = DateTime->new;
my $gdt = Module::Generic::DateTime->new( $dt );
# or directly will instantiate a default DateTime value based on DateTime->now
my $gdt = Module::Generic::DateTime->new;
# Now you can do operations that are not normally possible with DateTime
# Compare a dt object with a unix timestamp
if( $gdt > time() )
{
# do something
}
elsif( $gdt < '2020-03-01 07:12:10+0900' )
{
# do something
}
# and of course, comparison with other dt works as before
elsif( $gdt >= $dt )
{
# do something
}
# Remove 10 seconds from time object
$gdt -= 10;
# Add 5 seconds and get a new object
my $dt2 = $gdt + 5;
# Get the difference as an interval between two objects
my $interval = $dt1 - $dt2;
# DateTime::Duration are represented by Module::Generic::DateTime::Interval
# and extra manipulations are possible
# Add 7 seconds
$int += 7;
# Change the days
$int->days( 5 );
# or using lvalue
$int->days = 5;
# or multiply everything (years, months, weeks, days, hours, minutes, seconds and nanoseconds) in the interval by 2
$int *= 2
# Multiply one interval by another:
my $new_interval = $int1 * $int2;
# or multiply with assignment
$int1 *= $int2;
# Then add the interval to the datetime object
$dt += $int;
π VERSION π
v0.6.2 β periodt.
πΈ DESCRIPTION πΈ
Module::Generic::DateTime is a thin wrapper around DateTime to provide additional features as exemplified above.
It also enables the DateTime object to be thawed and frozen and converted to JSON with the respective methods STORABLE_freeze, STORABLE_thaw, TO_JSON.
All other method calls not in this API are passed to DateTime using AUTOLOAD with the added benefit that, if a method called triggers a fatal exception, it is caught using Nice::Try try-catch block and an error is set and return is returned instead. lowkey iconic error handling ππ
π οΈ CONSTRUCTOR π οΈ
new
Provided with an optional DateTime object and this returns a new instance of Module::Generic::DateTime.
If no DateTime object was provided, this will instantiate one implicitly and set the formatter to stringify it to an iso8601 string, such as: 2022-03-08T14:22:10+0000. By default the instantiated DateTime object use the default time zone, which is GMT. You can change the time zone afterward using set_time_zone in DateTime:
$dt->set_time_zone( 'Asia/Tokyo' );
from_epoch
my $d = Module::Generic::DateTime->from_epoch( epoch => $unix_timestamp );
Instantiate a new Module::Generic::DateTime using the DateTime method from_epoch. Any parameters are passed through to from_epoch in DateTime.
If a DateTime error occurs, it will be caught and an error will be set and undef will be returned.
now
my $d = Module::Generic::DateTime->now;
Instantiate a new Module::Generic::DateTime using the DateTime method now. Any parameters are passed through to now in DateTime.
If a DateTime error occurs, it will be caught and an error will be set and undef will be returned.
π§ METHODS π§
as_string
This is an alias to stringify.
datetime
Sets or gets the underlying DateTime object.
op
This method is called to overload the following operations:
""stringificationbool">"greater than">="greater or equal than"<"lower than"<="lower or equal than"=="euqal β that's exactly how the doc spells it, bestie π"!="not equal"-"minus"+"plus
op_minus_plus
This method handles cases of overloading for minus and plus.
π¦ SERIALISATION π¦
Serialisation by CBOR, Sereal and Storable::Improved (or the legacy Storable) is supported by this package. To that effect, the following subroutines are implemented: FREEZE, THAW, STORABLE_freeze and STORABLE_thaw.
Additionally, upon loading Module::Generic::DateTime, it will ensure the following DateTime modules also have a FREEZE and THAW subroutines if not defined already:
DateTimeDateTime::TimeZoneDateTime::TimeZone::OffsetOnlyDateTime::Locale::FromDataDateTime::Locale::Base
π§΅ THREAD & PROCESS SAFETY π§΅
Module::Generic::DateTime is designed to be fully thread-safe and process-safe, ensuring data integrity across Perl ithreads and mod_perlβs threaded Multi-Processing Modules (MPMs) such as Worker or Event. It relies on Module::Generic::Global for thread-safe storage of shared state and employs synchronisation mechanisms to prevent data corruption and race conditions. no cap π§΅β¨
Synchronisation Mechanisms
- Shared State β The module uses
Module::Generic::Globalto cache the availability of the systemβs local timezone in thelocal_tznamespace, storing a boolean (0or1) indicating whether the local timezone is supported. This repository is:sharedwhenCAN_THREADSis true (Perl supports ithreads), protected bylockin perlfunc for Perl threads orAPR::ThreadRWLockfor mod_perl threaded MPMs without threads. In non-threaded environments, the repository is shared across processes, requiring no additional synchronisation. - DateTime Operations β Methods like
opandop_minus_plusperform timezone checks andDateTimeoperations, which are thread-safe as they rely onModule::Generic::Globalβs synchronisation. The underlyingDateTimemodule is thread-safe for most operations, and this module ensures no shared mutable state is accessed without proper locking.
Context Key Isolation
The local_tz namespace uses a class-level key (<class>), where class is Module::Generic::DateTime. This ensures timezone support is cached across processes, with no thread-specific granularity needed, as timezone availability is a global property. The key format enables cross-process sharing, and threaded environments (HAS_THREADS true) maintain isolation via Module::Generic::Globalβs synchronisation.
mod_perl Considerations
- Prefork MPM β Data is cross-process, requiring no additional synchronisation, as all processes share the same
local_tzrepository. - Threaded MPMs (Worker/Event) β The
local_tzrepository is shared across threads and processes, protected byModule::Generic::Globalβs synchronisation. Users should callModule::Generic::Global-`cleanup_register>in mod_perl handlers to clear the repository after requests, preventing memory leaks in long-running processes. - Thread-Unsafe Functions β Avoid Perl functions like
localtime,readdir,srand, or operations likechdir,umask,chrootin threaded MPMs, as they may affect all threads. Consultperlthrtut(http://perldoc.perl.org/perlthrtut.html) and mod_perl documentation (https://perl.apache.org/docs/2.0/user/coding/coding.html#Thread_environment_Issues) for details.
Thread-Safety Considerations
The moduleβs thread-safety relies on:
- Shared Repository β The
local_tznamespace is initialised as:sharedwhenCAN_THREADSis true, ensuring safe access across threads and processes. - Locking β
lockin perlfunc orAPR::ThreadRWLockprotects all read/write operations to the repository. - Immutable State β Beyond
local_tz, the module avoids shared mutable state, relying onDateTimeβs thread-safe operations.
In environments where %INC manipulation (e.g., by forks) emulates threads, HAS_THREADS and IN_THREAD may return true. This is generally safe, as forks provides a compatible tid method, but users in untrusted environments should verify $INC{'threads.pm'} points to the actual threads module.
For maximum safety, users running mod_perl with threaded MPMs should ensure Perl is compiled with ithreads and explicitly load threads, or use Prefork MPM for single-threaded operation.
π SEE ALSO π
Module::GenericModule::Generic::DateTime::IntervalDateTimeDateTime::Format::StrptimeDatetTime::TimeZoneβ yes, exactly like that; the extra βtβ is in the doc, bestie π
π AUTHOR π
Jacques Deguest <jack@deguest.jp> β say hi, bestie π«Ά
Β©οΈ COPYRIGHT & LICENSE Β©οΈ
Copyright (c) 2000-2024 DEGUEST Pte. Ltd.
You can use, copy, modify and redistribute this package and associated files under the same terms as Perl itself. slay π
okay that's the whole page, bestie π this one came from perl v5.42.2, dated 2026-02-15, and the manual is Module:...DateTime(3). bye bestie, go compare some timestamps β¨π¦
π¦ where this page comes from
- alpine 3.24: perl-module-generic-doc 1.1.3-r1 Β· GPL-1.0-or-later OR Artistic-1.0-Perl
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms