From d035f457090dc467e035666978464c5ad2303d79 Mon Sep 17 00:00:00 2001 From: Florian Fischer Date: Mon, 9 Jan 2017 18:52:42 +0100 Subject: fix and simplify the range extraction year_offsets are now correct calculated. --- mark.fish | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/mark.fish b/mark.fish index 2df69e5..8e5b348 100644 --- a/mark.fish +++ b/mark.fish @@ -61,9 +61,9 @@ function __mark_get --description 'extract information from a mark_store' \ set start_d (string split "-" (date -d @$start_s +%Y-%m-%d)) set year_diff (math $year - $start_d[1]) - set first_year_offset (math "$year_offset + 12*$year_diff") + set first_year_offset (math "$year_offset - 13*$year_diff") - if test $first_year_offset -gt (count marks) + if test $first_year_offset -le 0 echo range is to big for available data! >&2 return 1 end @@ -72,30 +72,26 @@ function __mark_get --description 'extract information from a mark_store' \ # $s = oldest month to add set s $start_d[2] set e 12 - for y in (seq $first_year_offset -12 $year_offset) + for y in (seq $first_year_offset +13 $year_offset) # set e if last year is reached if test $y -eq $year_offset set e $month end for i in (seq $s $e) - set range_marks $range_marks (string split ":" $marks[(math $y + $i)])[2] + set line_marks (string split ":" $marks[(math $y + $i)])[2] + # ignore empty lines (years :\n) + if not test "" = $line_marks + set range_marks $range_marks $line_marks + end end # reset s -> start with january set s 0 end - set marks (string split "" $range_marks[1]) + set marks (string split "" $range_marks) + + set marks $marks[$start_d[3]..(math $start_d[3] + $range)] - if test (count $range_marks) -gt 1 - set marks $marks[$start_d[3]..-1] - for i in (seq 2 (math (count $range_marks) - 1)) - set marks $marks (string split "" $range_marks[$i]) - end - set tmp_marks (string split "" $range_marks[-1]) - set marks $marks $tmp_marks[1..$day] - else - set marks $marks[$start_d[3]..$day] - end echo (string join "" $marks) else set marks (string split "" (string split ":" $marks[(math $month+$year_offset)])[2]) -- cgit v1.2.3