Skip to content

Commit

Permalink
tweaked examples. All examples now pass R cmd check
Browse files Browse the repository at this point in the history
  • Loading branch information
garrettgman committed Feb 7, 2012
1 parent 9fd98da commit 3d94ad1
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 32 deletions.
30 changes: 15 additions & 15 deletions R/timespans.r
Expand Up @@ -90,13 +90,13 @@ is.timespan <- function(x) is(x, "Timespan")
#' \code{\link{new_interval}} for creating interval objects
#' @keywords classes chron
#' @examples
#' new_duration(second = 3690)
#' duration(second = 3690)
#' # 3690s (1.02h)
#' new_period(second = 3690)
#' period(second = 3690)
#' # 3690 seconds
#' new_period(second = 30, minute = 1, hour = 1)
#' period(second = 30, minute = 1, hour = 1)
#' # 1 hour, 1 minute and 30 seconds
#' new_interval(ymd_hms("2009-08-09 13:01:30"), ymd_hms("2009-08-09 12:00:00"))
#' interval(ymd_hms("2009-08-09 13:01:30"), ymd_hms("2009-08-09 12:00:00"))
#' # 2009-08-09 12:00:00 -- 2009-08-09 13:01:30
#'
#' date <- as.POSIXct("2009-03-08 01:59:59") # DST boundary
Expand All @@ -108,24 +108,24 @@ is.timespan <- function(x) is(x, "Timespan")
#'
#' date2 <- as.POSIXct("2000-02-29 12:00:00")
#' date2 + years(1)
#' # "2001-02-28 12:00:00 CST"
#' # self corrects to most recent real day
#' # "2001-03-01 12:00:00 CST"
#' # self corrects to next real day
#'
#' date3 <- as.POSIXct("2009-01-31 01:00:00")
#' date3 + c(0:11) * months(1)
#' # [1] "2009-01-31 01:00:00 CST" "2009-02-28 01:00:00 CST"
#' # [3] "2009-03-31 01:00:00 CDT" "2009-04-30 01:00:00 CDT"
#' # [5] "2009-05-31 01:00:00 CDT" "2009-06-30 01:00:00 CDT"
#' # [1] "2009-01-31 01:00:00 CST" "2009-03-03 01:00:00 CST"
#' # [3] "2009-03-31 01:00:00 CDT" "2009-05-01 01:00:00 CDT"
#' # [5] "2009-05-31 01:00:00 CDT" "2009-07-01 01:00:00 CDT"
#' # [7] "2009-07-31 01:00:00 CDT" "2009-08-31 01:00:00 CDT"
#' # [9] "2009-09-30 01:00:00 CDT" "2009-10-31 01:00:00 CDT"
#' #[11] "2009-11-30 01:00:00 CST" "2009-12-31 01:00:00 CST"
#' # [9] "2009-10-01 01:00:00 CDT" "2009-10-31 01:00:00 CDT"
#' # [11] "2009-12-01 01:00:00 CST" "2009-12-31 01:00:00 CST"
#'
#' span <- date2 - date #creates interval
#' # 2000-02-29 12:00:00 -- 2009-03-08 01:59:59
#' span <- date2 %--% date #creates interval
#' # "2000-02-29 12:00:00 CST--2009-03-08 01:59:59 CST"
#' span - days(294)
#' # 2000-02-29 12:00:00 -- 2008-05-18 01:59:59
#' # "2008-05-18 01:59:59 CDT--2000-02-29 12:00:00 CST"
#' span - ddays(294)
#' # 2000-02-29 12:00:00 -- 2008-05-18 02:59:59
#' # "2000-02-29 12:00:00 CST--2008-05-18 02:59:59 CDT"
#'
#' date <- as.POSIXct("2009-01-01 00:00:00")
#' # "2009-01-01 GMT"
Expand Down
4 changes: 2 additions & 2 deletions man/decimal_date.Rd
Expand Up @@ -15,8 +15,8 @@
Converts a date to a decimal of its year.
}
\examples{
date <- as.POSIXlt("2009-02-10")
decimal_date(date) # 2009.109
date <- ymd("2009-02-10")
decimal_date(date) # 2009.11
}
\keyword{chron}
\keyword{manip}
Expand Down
30 changes: 15 additions & 15 deletions man/timespan.Rd
Expand Up @@ -75,13 +75,13 @@
always positive.
}
\examples{
new_duration(second = 3690)
duration(second = 3690)
# 3690s (1.02h)
new_period(second = 3690)
period(second = 3690)
# 3690 seconds
new_period(second = 30, minute = 1, hour = 1)
period(second = 30, minute = 1, hour = 1)
# 1 hour, 1 minute and 30 seconds
new_interval(ymd_hms("2009-08-09 13:01:30"), ymd_hms("2009-08-09 12:00:00"))
interval(ymd_hms("2009-08-09 13:01:30"), ymd_hms("2009-08-09 12:00:00"))
# 2009-08-09 12:00:00 -- 2009-08-09 13:01:30

date <- as.POSIXct("2009-03-08 01:59:59") # DST boundary
Expand All @@ -93,24 +93,24 @@ date + edays(1)

date2 <- as.POSIXct("2000-02-29 12:00:00")
date2 + years(1)
# "2001-02-28 12:00:00 CST"
# self corrects to most recent real day
# "2001-03-01 12:00:00 CST"
# self corrects to next real day

date3 <- as.POSIXct("2009-01-31 01:00:00")
date3 + c(0:11) * months(1)
# [1] "2009-01-31 01:00:00 CST" "2009-02-28 01:00:00 CST"
# [3] "2009-03-31 01:00:00 CDT" "2009-04-30 01:00:00 CDT"
# [5] "2009-05-31 01:00:00 CDT" "2009-06-30 01:00:00 CDT"
# [1] "2009-01-31 01:00:00 CST" "2009-03-03 01:00:00 CST"
# [3] "2009-03-31 01:00:00 CDT" "2009-05-01 01:00:00 CDT"
# [5] "2009-05-31 01:00:00 CDT" "2009-07-01 01:00:00 CDT"
# [7] "2009-07-31 01:00:00 CDT" "2009-08-31 01:00:00 CDT"
# [9] "2009-09-30 01:00:00 CDT" "2009-10-31 01:00:00 CDT"
#[11] "2009-11-30 01:00:00 CST" "2009-12-31 01:00:00 CST"
# [9] "2009-10-01 01:00:00 CDT" "2009-10-31 01:00:00 CDT"
# [11] "2009-12-01 01:00:00 CST" "2009-12-31 01:00:00 CST"

span <- date2 - date #creates interval
# 2000-02-29 12:00:00 -- 2009-03-08 01:59:59
span <- date2 \%--\% date #creates interval
# "2000-02-29 12:00:00 CST--2009-03-08 01:59:59 CST"
span - days(294)
# 2000-02-29 12:00:00 -- 2008-05-18 01:59:59
# "2008-05-18 01:59:59 CDT--2000-02-29 12:00:00 CST"
span - ddays(294)
# 2000-02-29 12:00:00 -- 2008-05-18 02:59:59
# "2000-02-29 12:00:00 CST--2008-05-18 02:59:59 CDT"

date <- as.POSIXct("2009-01-01 00:00:00")
# "2009-01-01 GMT"
Expand Down

0 comments on commit 3d94ad1

Please sign in to comment.