Skip to content

Instantly share code, notes, and snippets.

@jesusbagpuss
Created December 1, 2022 09:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jesusbagpuss/8b899eb0eb9b2b733eead25c6dfd5973 to your computer and use it in GitHub Desktop.
Save jesusbagpuss/8b899eb0eb9b2b733eead25c6dfd5973 to your computer and use it in GitHub Desktop.
EPrints field to get creation date
# Return this datestamp from the first history item of this record - the creation date.
#
# requires https://bazaar.eprints.org/452/1/plugins/EPrints/MetaField/Virtualwithvalue.pm
# (and some phrases)
$c->add_dataset_field( "eprint",
{
name => 'creation_date',
type => 'virtualwithvalue',
virtual => 1,
get_value => sub
{
my ( $field, $eprint ) = @_;
my $repo = $eprint->repository;
my @filters = (
{ meta_fields => [qw( datasetid )], value => 'eprint', },
{ meta_fields => [qw( objectid )], value => $eprint->id, },
);
my $hist_list = $repo->dataset( "history" )->search(
filters => \@filters,
custom_order=>"historyid",
limit => 1,
);
my $first_hist = $hist_list->item( 0 );
if( defined $first_hist )
{
my $ts = $first_hist->value( "timestamp" );
my( $date, $time ) = split / /, $ts;
return $date if defined $date;
}
return;
},
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment