Datetimes as Integers for Discrete-Event Simulations

Handles datetimes as integers for the usage inside Discrete-Event Simulations (DES). The conversion is made using the internally generic function as.numeric() of the base package. DES is described in Simulation Modeling and Analysis by Averill Law and David Kelton (1999) .


simtimer in a little R package designed to simplify (and speeding up) calculating time intervals in discrete event simulations.

Discrete event simulations is a simulation paradigm that is based on the evaluation of events taking place in a time-specific order. Therefore a discrete event simulation calculates many time intervals. simtimer handles dates and times as integers. This makes working with time intervals as easy (and as fast) as subtracting integers.


You can install simtimer from CRAN or github with:



Simtimer allows transformation between datetimes (POSIXt) and sim_datetimes (integer) with sim_datetime() and datetime().

origin_date <- as.POSIXct("2016-01-01 00:00:00", tz = "UTC")
my_datetime <-  as.POSIXct("2016-01-02 01:01:01", tz = "UTC")
my_simdatetime <- as.sim_datetime(my_datetime, origin_date)
#> [1] 90061
as.datetime(my_simdatetime, origin_date)
#> [1] "2016-01-02 01:01:01 UTC"

Simtimer allows to manipulate sim_datetimes and extract parts of sim_datetimes with sim_time(), sim_wday() and sim_date().

#> [1] 3661
sim_wday(my_simdatetime, origin_date)
#> [1] "6"
#> [1] 1


simtimer 4.0.0

  • Adapt return_value of simtimer::sim_wday() to a character, giving the weekday number ("1" = Monday, "2" = Tuesday, ..., "7" = Sunday). Before this function returned the abbreviated weekday (depending on base::Sys.getlocale()). The new solution therefore improves platform independency.
  • decoupling of lubridate package by replacement with base functions.

simtimer 3.0.0

  • Added a file to track changes to the package.
  • Basic functionality as described in and vignette.

Reference manual

It appears you don't have a PDF plugin for this browser. You can click here to download the reference manual.


4.0.0 by Adrian Staempfli, a year ago

Browse source code at

Authors: Adrian Staempfli , Christoph Strauss , Michael Schmid

Documentation:   PDF Manual  

GPL-3 license

Suggests testthat, knitr, rmarkdown, microbenchmark

See at CRAN