Created
March 3, 2017 15:52
-
-
Save jesusbagpuss/491086533294f864de63115c66719def to your computer and use it in GitHub Desktop.
Additions to EPrints::Script::Compiled for WRRO
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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