# [R] Problem with timeSequence {timeDate} - wrong end date

Martin Maechler maechler at stat.math.ethz.ch
Fri Jan 7 15:59:44 CET 2011

```>>>>> Joshua Wiley <jwiley.psych at gmail.com>
>>>>>     on Thu, 6 Jan 2011 06:47:43 -0800 writes:

> On Thu, Jan 6, 2011 at 5:27 AM, Joshua Wiley <jwiley.psych at gmail.com> wrote:
>> timeSequence() ultimately is relying on seq.POSIXt().  If you look at

> My apologies, I spoke nonsense---timeSequence() does NOT rely on
> seq.POSIXt().  The timeDate package has its own method defined for
> seq() which is what gets dispatched.  Still, the behavior is similar:

>> timeSequence(from = "2010-01-15", to = "2010-02-01", by = "1 month")
> GMT
> [1] [2010-01-15] [2010-02-15]
>>
>> seq.POSIXt(from = as.POSIXct("2010-01-15"),
> +   to = as.POSIXct("2010-02-01"), by = "1 month")
> [1] "2010-01-15 PST" "2010-02-15 PST"

> which is not surprising because the code is responsible for this
> behavior is similar:

> ###### seq.timeDate* ######
> else if (valid == 6) {
> if (missing(to)) {
> mon <- seq.int(r1\$mon, by = by, length.out = length.out)
> }
> else {
> to <- as.POSIXlt(to)
> mon <- seq.int(r1\$mon, 12 * (to\$year - r1\$year) +
> to\$mon, by)
> }
> r1\$mon <- mon
> r1\$isdst <- -1
> res <- as.POSIXct(r1)
> }

> ###### seq.POSIXt ######
> else if (valid == 6L) {
> if (missing(to)) {
> mon <- seq.int(r1\$mon, by = by, length.out = length.out)
> }
> else {
> to <- as.POSIXlt(to)
> mon <- seq.int(r1\$mon, 12 * (to\$year - r1\$year) +
> to\$mon, by)
> }
> r1\$mon <- mon
> r1\$isdst <- -1
> res <- as.POSIXct(r1)
> }

> and "res" is the object returned in both cases (I believe).

Thank you, Joshua.

Note that "R 2.12.1 patched" and "R 2.13.0 unstable"
have this fixed (since yesterday) and hence will no longer "overshoot".

Also, the next release of the  timeDate  package will have it
fixed.

Martin Maechler, ETH Zurich

> My system:
> R version 2.12.1 (2010-12-16)
> Platform: i486-pc-linux-gnu (32-bit)

> locale:
> [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C
> [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8
> [5] LC_MONETARY=C              LC_MESSAGES=en_US.UTF-8
> [7] LC_PAPER=en_US.UTF-8       LC_NAME=C
> [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C

> attached base packages:
> [1] stats     graphics  grDevices utils     datasets  methods   base

> other attached packages:
> [1] timeDate_2130.91

> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help