Data::...ateTime(3pm)
π NAME π
Data::Faker::DateTime β bestie, it's a Data::Faker plugin. That's the whole vibe. It makes fake dates and times for you. π
(also the header says this is User Contributed Perl Documentation and the page lives at Data::...ateTime(3pm) β yes the title is literally truncated like that, no that's not me being lazy, that's just how the page header is written π)
β¨ SYNOPSIS AND USAGE β¨
okay so like, go see Data::Faker. That's it. That's the usage. fr fr. π¦
πΈ DATA PROVIDERS πΈ
These are the little functions you can call. One bullet each, we're not skipping a single one, periodt.
unixtimeβ hands you a unix time (that's seconds since the epoch, iykyk) for a random moment somewhere between the epoch and right now.dateβ a random date, as a string, using a random date format (peepdate_formatfor that).timeβ a random time, as a string, using a random time format (seetime_format).rfc822β a random date all formatted up in RFC 822 style. β οΈ heads up: this one might not work on systems running a non-GNUstrftime, and the author is like "kindly let me know if that's the case." So if it breaks, tell him, bestie.ampmβ returnsamorpmat random, in the current locale, using one of the formats listed inampm_format.time_formatβ a random time format.date_formatβ a random date format.ampm_formatβ a random am/pm format.datetime_formatβ a random date-and-time format.monthβ a random month name, unabbreviated, in the current locale.month_abbrβ a random month name, abbreviated, in the current locale.weekdayβ a random weekday name, unabbreviated, in the current locale.weekday_abbrβ a random weekday name, abbreviated, in the current locale.sqldateβ a random date in the ISO8601 format that SQL servers are obsessed with (YYYY-MM-DD).datetime_localeβ a datetime string in the preferred date representation for the current locale, for a random date.date_localeβ a date string in the preferred date representation for the current locale, for a random date.time_localeβ a time string in the preferred date representation for the current locale, for a random date.centuryβ a random century number.dayofmonthβ a random day of the month.
π§ UTILITY METHODS π§
Data::Faker::DateTime::timestr($format);
You hand it a strftime format specifier, and it passes that specifier through to POSIX::strftime along with a random date, so the date shows up in whatever format you asked for. iconic behaviour honestly.
Perl passes this through to the strftime function of your system library, so lowkey it's possible that some of the formatting tokens used here just won't work on your system. not me warning you twice, but here we are. π
π NOTES AND CAVEATS π
Be careful building timestamps from pieces
Bestie. Listen. Be very careful about building date/time representations in formats that aren't already listed here. For example, if you wanted a date that's just the month and the day? You should NOT do this:
my $faker = Data::Faker->new();
print join(' ',$faker->month,$faker->dayofmonth)."\n";
This is bad, and here's why: you might end up with 'February 31'. Yes. A date that does not exist. π
Instead you should use the timestr utility function to get a formatted time for a valid date, or β better still β write a plugin function that does it for you:
my $faker = Data::Faker->new();
print $faker->my_short_date()."\n";
package Data::Faker::MyExtras;
use base qw(Data::Faker);
use Data::Faker::DateTime;
__PACKAGE__->register_plugin(
my_short_date => sub { Data::Faker::DateTime::timestr('%M %e') },
);
look at that, a whole plugin, main character energy. β¨
POSIX::strftime
See the documentation above re: the timestr utility method for some caveats related to strftime and your system library. (yes it's the same caveat, no I will not elaborate, click up β¬οΈ)
π SEE ALSO π
Data::Faker
π AUTHOR π
Jason Kohles, <email@jasonkohles.com>
π«Ά COPYRIGHT AND LICENSE π«Ά
Copyright 2004-2005 by Jason Kohles
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
and that's the whole page babes π
this was perl v5.36.0, dated 2022-10-22, and it's a Data::...ateTime(3pm) situation through and through. go forth and generate fake dates responsibly, mwah π
π¦ where this page comes from
- ubuntu noble: libdata-faker-perl 0.10-4 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libdata-faker-perl 0.10-4 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libdata-faker-perl 0.10-4 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms