Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Additions to EPrints::Script::Compiled for WRRO
# Open block
{
# Write into EPrints::Script::Compiled
package EPrints::Script::Compiled;
use strict;
# Render event dates when used in citation
# This will not affect them when exported/in the database.
# Add to the workflow with:
# <if test="event_dates"><print expr="wrro_human_event_dates(event_dates)"/></if>
#
sub run_wrro_human_event_dates
{
my( $self, $state, $value ) = @_;
my $session = $state->{session};
my $event_dates = $value->[0]; #[1] = MetaField, [2] = EPrint
my $r;
if( $event_dates =~ m/^\s*\d{4}\-\d{2}\-\d{2}\s*$/ ) {
# YYYY-MM-DD : Just one date - render it in short style
$r = EPrints::Utils::tree_to_utf8( EPrints::Time::render_short_date( $session, $event_dates ) );
} elsif( $event_dates =~ m/^\s*(\d{4}\-\d{2}\-\d{2})\s*\-\s*(\d{4}\-\d{2}\-\d{2})\s*$/ ) {
# YYYY-MM-DD - YYYY-MM-DD - start and finish dates.
if( $1 eq $2 ){
# start date = finish date : render it in short style
$r = EPrints::Utils::tree_to_utf8( EPrints::Time::render_short_date( $session, $1 ) );
} else {
my @start_date = EPrints::Time::split_value( $1 );
my @finish_date = EPrints::Time::split_value( $2 );
if( $start_date[0] != $finish_date[0] ){
#different years: 30 Dec 2014 - 2 Jan 2015
$r = EPrints::Utils::tree_to_utf8( EPrints::Time::render_short_date( $session, $1 ) ) .
' - ' .
EPrints::Utils::tree_to_utf8( EPrints::Time::render_short_date( $session, $2 ) );
} elsif( $start_date[1] != $finish_date[1] ){
#different months: 31 Jan - 2 Feb 2015
$r = $start_date[2].' '.EPrints::Time::short_month_label( $session, $start_date[1] ).' - ' .
EPrints::Utils::tree_to_utf8( EPrints::Time::render_short_date( $session, $2 ) );
} else {
# same year, same month, different days.
$r = $start_date[2] . '-' .
EPrints::Utils::tree_to_utf8( EPrints::Time::render_short_date( $session, $2 ) );
}
}
} else {
#something that doesn't match YYYY-MM-DD - render it as-is.
$r = $event_dates;
}
return [ $r, "STRING" ];
}
# END EPrints::Script::Compiled additions
}
#Close block
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.