Phil Taylor <tabanid <at> gmail.com> writes:
>
> Hi ...
>
> I wonder if anyone can provide some insight into why the first three
> examples using the sunriset function (appended below, with results) give
> the correct answer, but the fourth generates and error.
>
> The first two use ISOdatetime with and without a time zone attribute,
> and the sunriset function returns the correct sunset time.
>
> The third and fourth adds 10 seconds to the ISOdatetime (with and
> without the time zone attribute) but the function only works when the
> time zone is specified (example 3).
>
> When I look at the objects (print or str) they appear the same, and when
> I check to see if they are equivalent (e.g.)
>
> > time.1 <- ISOdatetime(1970, 1, 1, 10, 0, 0) + 10
> > time.2 <- ISOdatetime(1970, 1, 1, 10, 0, 0, tz="GMT") +
10
> > time.1 == time.2
> [1] TRUE
>
> they appear to be the same.
>
> I wonder if I am either missing something important, doing something
> improperly, or if there is a small bug somewhere.
There may be a misunderstanding, but a small bug is also possible. In an
internal call to as.POSIXct(), a NULL value was being passed to the tz=
argument when 10 seconds had been added and tz= not given in ISOdatetime().
In forthcoming maptools 0.7-18, the value being passed is tested, and the
tzargument dropped if the value is NULL. With this:
> library(maptools)
Loading required package: foreign
Loading required package: sp> Sys.setenv(TZ = "GMT")
> location <- matrix(c(-80.1,42.5), nrow=1)
> sunriset(location, ISOdatetime(1970, 1, 1, 10, 0, 0, tz="GMT"),
direction="sunset", POSIXct.out=TRUE)
day_frac time
newlon 0.915226 1970-01-01 21:57:55> sunriset(location, ISOdatetime(1970, 1, 1, 10, 0, 0),
direction="sunset",
POSIXct.out=TRUE)
day_frac time
newlon 0.915226 1970-01-01 21:57:55> sunriset(location, ISOdatetime(1970, 1, 1, 10, 0, 0, tz="GMT") +
10,
direction="sunset", POSIXct.out=TRUE)
day_frac time
newlon 0.915226 1970-01-01 21:57:55> sunriset(location, ISOdatetime(1970, 1, 1, 10, 0, 0) + 10,
direction="sunset", POSIXct.out=TRUE)
day_frac time
newlon 0.915226 1970-01-01 21:57:55
Thanks for the report - it could well be that the time classes are not being
used well here - in addition, the sunset etc. functions of course only look
at yearday, so adding 10 seconds isn't very meaningful, but I guess this is
a simple example of a real problem.
Roger Bivand
>
> I'm using windows Vista and R 2.8.1
>
> Thanks,
>
> Phil Taylor
> ptaylor <at> resalliance.org
>