// // Copyright 2019 SenX S.A.S. // // This program is free software: you can redistribute it and/or modify it // under the terms of the GNU Affero General Public License as published // by the Free Software Foundation, version 3. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty // of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. // See the GNU Affero General Public License for more details. // // You should have received a copy of the GNU Affero General Public License // along with this program. If not, see // <% SAVE '.context' STORE 'period' STORE // // Compute the bounds of the archive period // and the name of the previous and next periods // $period SIZE <% DUP 4 == %> // YYYY <% DROP $period '-01-01T00:00:00Z' TOTIMESTAMP 'start' STORE $start 1 ADDYEARS 1 - 'end' STORE $end 1 + ISO8601 0 4 SUBSTRING 'nextperiod' STORE $start -1 ADDYEARS ISO8601 0 4 SUBSTRING 'prevperiod' STORE %> <% DUP 6 == %> // YYYYMM <% DROP $period 0 4 SUBSTRING '-' + $period 4 2 SUBSTRING + '-01T00:00:00Z' + TOTIMESTAMP 'start' STORE $start 1 ADDMONTHS 1 - 'end' STORE $end 1 + ISO8601 0 7 SUBSTRING '-' '' REPLACE 'nextperiod' STORE $start -1 ADDMONTHS ISO8601 0 7 SUBSTRING '-' '' REPLACE 'prevperiod' STORE %> <% DUP 8 == %> // YYYYMMDD <% DROP $period 0 4 SUBSTRING '-' + $period 4 2 SUBSTRING + $period 6 2 SUBSTRING + 'T00:00:00Z' + TOTIMESTAMP 'start' STORE $start 1 ADDDAYS 1 - 'end' STORE $end 1 + ISO8601 0 10 SUBSTRING '-' '' REPLACEALL 'nextperiod' STORE $start -1 ADDDAYS ISO8601 0 10 SUBSTRING '-' '' REPLACEALL 'prevperiod' STORE %> <% 'Invalid archival period specification, expected YYYY, YYYYMM or YYYYMMDD' MSGFAIL %> 3 SWITCH $start $end $nextperiod $prevperiod $.context RESTORE %>