From c55aad1aea171771e7f1eea38e049b1d3a0fd788 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Turbelin?= Date: Wed, 5 Dec 2018 12:16:46 +0100 Subject: [PATCH] check dates in season history --- R/platform.R | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/R/platform.R b/R/platform.R index a308539..58882c8 100644 --- a/R/platform.R +++ b/R/platform.R @@ -479,6 +479,26 @@ platform_season_history <- function(season, dates, ...) { } def = list(...) def$dates = dates + + check_date = function(v, after=NULL) { + if(is.na(v)) { + return() + } + d = as.Date(v) + if(is.na(d)) { + stop(paste0(deparse(substitute(v)), "Unable to parse date '", v,"'")) + } + if(!is.null(after) ) { + after = as.Date(after) + if(d < after) { + stop(paste(deparse(substitute(v)), "should be after", after)) + } + } + } + + check_date(dates$start) + check_date(dates$end, after=dates$start) + .Share$historical.tables[[as.character(season)]] <- def } @@ -515,4 +535,4 @@ platform_options = function(...) { #' @export platform_env <- function() { .Share -} \ No newline at end of file +}