Catman...stamps(3pm)

πŸ“¦
version 1.2025 Β· 4 versions
, in ubuntu resolute, ubuntu stonking

πŸ’– Catman...stamps(3pm) β€” User Contributed Perl Documentation πŸ’–

okay bestie, sit down, hydrate, because we're about to talk about Catmandu::Plugin::Datestamps and honestly? it's giving "tiny plugin, enormous slay". πŸŽ€


✨ NAME ✨

Catmandu::Plugin::Datestamps β€” automatically add datestamps to Catmandu::Store records πŸ•βœ¨

like. it stamps dates. on your records. automatically. no cap.


πŸ¦‹ SYNOPSIS πŸ¦‹

first up, the config file route, because that's the vibe:

# Using configuration files

$ cat catmandu.yml
---
store:
 test:
   package: MongoDB
   options:
     database_name: test
     bags:
       data:
         plugins:
           - Datestamps

$ echo '{"hello":"world"}' | catmandu import JSON to test
$ catmandu export test to YAML
---
_id: ADA305D8-697D-11E3-B0C3-97AD572FA7E3
date_created: 2013-12-20T13:50:25Z
date_updated: 2013-12-20T13:50:25Z
hello: world

see how date_created and date_updated just appeared?? not me gasping. 😭✨ that's the plugin doing its lil thing.

or, if you're a Perl program kinda girlie, you can do it inline:

# Or in your Perl program
my $store = Catmandu::Store::MongoDB->new(
           database_name => 'test' ,
           bags => {
               data => {
               plugins => [qw(Datestamps)]
           }
       });

$store->bag->add({
       '_id'  => '123',
       'name' => 'John Doe'
});

my $obj = $store->bag->get('123');

print "%s created at %s\n" , $obj->{name} , $obj->{date_created};

slay. you add a record, you get it back, the date is right there. main character behavior fr fr. πŸ’…


🌸 DESCRIPTION 🌸

so here's the tea. the Catmandu::Plugin::Datestamps plugin automatically adds and updates datestamp fields in your records. that's it, that's the job, and it does it flawlessly. πŸ‘‘

if you add this plugin to your Catmandu::Store configuration, then a date_created field and a date_updated field get added automatically to newly ingested records. like, you didn't ask, and yet. iconic. ✨

heads up bestie: you should set this plugin for every bag defined in your Catmandu::Store. in the examples above we've set the plugin to the default bag data, which is the one created in every Catmandu::Store.

and here's the part where you gotta listen carefully 🫢 β€” in Catmandu::Stores that don't have a dynamic schema (thinking Solr, DBI), those new date fields should be predefined β€” like, by changing the schema.xml or the tables fields. do that or the vibe check fails. πŸ’€


πŸŽ€ CONFIGURATION πŸŽ€

datestamp_created_key

the field name where the creation date gets stored. defaults to date_created. it's also aliased as datestamp_created_field. two names, one legend. πŸ’–

datestamp_updated_key

the field name where the update date gets stored. defaults to date_updated. also aliased as datestamp_updated_field. same energy. ✨

datestamp_format

want a custom strftime format? say less. peep Catmandu::Util::now for the possible format values πŸ‘€

my $store = Catmandu::Store::MyDB->new(bags => {book => {plugins =>
    ['Datestamps'], datestamp_format => '%Y/%m/%d'}});

my $store = Catmandu::Store::MyDB->new(bags => {book => {plugins =>
    ['Datestamps'], datestamp_format => 'iso_date_time_millis'}});

one is giving classic slashes, the other is giving iso_date_time_millis. both ate. πŸ”₯


🌈 SEE ALSO 🌈

  • Catmandu::Store
  • Catmandu::Bag

go read those, iykyk πŸ¦‹


and that's the whole page, bestie!! this one shipped as perl v5.40.1, dated 2026-01-24, and it lives in your friendly neighborhood Catman...stamps(3pm) β€” user contributed Perl documentation, mwah πŸ’‹ go forth and datestamp responsibly. 🫢✨

πŸ“¦ where this page comes from