Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 74 additions & 0 deletions mason/breeders_toolbox/trial/trial_details.mas
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,74 @@ $latest_trial_activity => undef

</%args>

<%init>
my ($dap, $dah);

sub _normalize_to_ymd {
my ($s) = @_;
return undef unless defined $s;
$s =~ s/^\s+|\s+$//g;

# "YYYY-MonthName-DD" -> "YYYY-mm-dd" (e.g., 2025-November-14)
if ($s =~ /^(\d{4})[-\/](\p{L}+)[-\/](\d{1,2})$/) {
my ($y, $mon, $d) = ($1, lc($2), $3);
$mon =~ s/[^a-z]//g;

my %m = (
jan=>1, january=>1, feb=>2, february=>2, mar=>3, march=>3,
apr=>4, april=>4, may=>5, jun=>6, june=>6, jul=>7, july=>7,
aug=>8, august=>8, sep=>9, sept=>9, september=>9,
oct=>10, october=>10, nov=>11, november=>11, dec=>12, december=>12
);

my $mnum = $m{$mon} || $m{substr($mon,0,3)};
return $mnum ? sprintf("%04d-%02d-%02d", $y, $mnum, $d) : undef;
}

# "YYYY-m-d" or "YYYY/mm/dd" -> "YYYY-mm-dd"
if ($s =~ /^(\d{4})[-\/](\d{1,2})[-\/](\d{1,2})$/) {
return sprintf("%04d-%02d-%02d", $1, $2, $3);
}

return undef;
}

sub _days_since {
my ($date_str) = @_;
return undef unless $date_str;

my $ymd = _normalize_to_ymd($date_str);
return undef unless $ymd;

eval {
require Time::Piece;
my $tp = Time::Piece->strptime($ymd, '%Y-%m-%d');
my $today = Time::Piece::localtime();
my $diff_days = int( ($today - $tp) / (24*60*60) );
return ($diff_days >= 0) ? $diff_days : undef;
} || undef;
}

sub _positive_integer_conf {
my ($conf_name) = @_;
my $value = eval { $c->get_conf($conf_name) };
return undef unless defined $value && $value =~ /^\d+$/ && $value > 0;
return int($value);
}

sub _limit_days_display {
my ($days, $limit) = @_;
return undef unless defined $days;
return (defined $limit && $days >= $limit) ? '>'.$limit : $days;
}

$dap = _days_since($planting_date);
$dah = _days_since($harvest_date);
my $display_dap_dah = eval { $c->get_conf('display_dap_dah') } ? 1 : 0;
my $dap_display = $display_dap_dah ? _limit_days_display($dap, _positive_integer_conf('limit_dap')) : undef;
my $dah_display = $display_dap_dah ? _limit_days_display($dah, _positive_integer_conf('limit_dah')) : undef;
</%init>


<div class="row">
<div class="col-sm-8">
Expand Down Expand Up @@ -130,6 +198,9 @@ $latest_trial_activity => undef
<div id="planting_date">
% if ($planting_date) {
<a href="/breeders/trial/<% $trial_id %>?currentDate=<% $planting_date %>" ><% $planting_date %></a>
% if (defined $dap_display) {
&nbsp;<span>| DAP: <% $dap_display %> </span>
% }
% } else {
% print "<span class='text-danger'>[No Planting Date]</span>";
% }
Expand All @@ -152,6 +223,9 @@ $latest_trial_activity => undef
<div id="harvest_date">
% if ($harvest_date) {
<a href="/breeders/trial/<% $trial_id %>?currentDate=<% $harvest_date %>" ><% $harvest_date %></a>
% if (defined $dah_display) {
&nbsp;<span> | DAH: <% $dah_display %> </span>
% }
% } else {
% print "<span class='text-danger'>[No Harvest Date]</span>";
% }
Expand Down
6 changes: 6 additions & 0 deletions sgn.conf
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,12 @@ sample_tissue_types leaf,root,stem,seed,fruit,tuber
#Homepage controller customization
homepage_display_phenotype_uploads 0

#Trial details DAP/DAH display limits. Set to a positive integer to display
#values at or above that day count as ">limit". NULL disables the limit.
display_dap_dah 1
limit_dap 365
limit_dah 365

## banana ordering system
ordering_service_name NULL
ordering_service_url https://ona.io
Expand Down
Loading