NetLogo banner

Home
Download
Help
Resources
Extensions
FAQ
NetLogo Publications
Contact Us
Donate

Models:
Library
Community
Modeling Commons

Beginners Interactive NetLogo Dictionary (BIND)
NetLogo Dictionary

User Manuals:
Web
Printable
Chinese
Czech
Farsi / Persian
Japanese
Spanish

  Donate

NetLogo User Community Models

(back to the NetLogo User Community Models)

[screen shot]

Download
If clicking does not initiate a download, try right clicking or control clicking and choosing "Save" or "Download".(The run link is disabled because this model uses extensions.)

# TIME EXTENSION EXAMPLE: LOGOTIMES

## WHAT IS IT?

This is a simple demonstration of how to use NetLogo's time extension to represent real dates and times in a model. It shows how to create, manipulate, and output the "Logotime" variable type provided by the time extension.

Users should be able to copy code directly from this example into their own models. However, normally the time units and length of a tick are not parameters as they are here (explained below), but "hardwired" -- the `anchor-to-ticks` statement in `setup` normally looks like this:
```
set sim-time time:anchor-to-ticks sim-start-time 1 day
```

The NetLogo User Manual's section on the time extension provides much more detail and more examples.

A Logotime variable can hold one of three kinds of time values: a DATETIME--a date and time, with precision down to milliseconds; a DATE--a day specified by year, month, and date, but with no sub-daily information; and a DAY--a day of the year without specifying which year (e.g., April 15). This model uses only the DATETIME type.

This "model" simply ticks through a specified amount of time and reports the time at each tick in a variety of units.

## HOW IT WORKS

Comments in the Code tab explain how the model works.

## HOW TO USE IT

Users can explore how the time extension represents time by:

* Setting the dates and times at which the simulation starts and ends by editing the `sim-start-time` and `sim-end-time` inputs on the Interface. These are text strings that must be in the format: "yyyy/M/d HH:mm:ss" (year, month, day, hour, minute, seconds).
* Selecting the time step units from the Interface chooser. The chooser offers most but not all of the time periods supported by the time extension, from years down to seconds.
* Using the slider to set the time step length. If the units are chosen as "days" and time step length is set to 1.5, then each tick will represent 1.5 days.
* Clicking `setup`.
* Clicking `step` to update the time one tick, or `go` for repeated updates.
* Observe the simulation time in various units, in the monitors on the Interface.

Note that changes in the time step units and length only take effect in the `setup` procedure. Changing them during a simulation has no effect--you must set up again for changes in start time, end time, or the time step to take effect.

Setting the Interface to view updates on ticks (instead of "Continuous") may make the model run slow enough to observe; if not, turn down the speed slider.

## THINGS TO NOTICE

Non-integer time step lengths are not supported for units of "months" or "years"; for months and years, the time step length will be rounded to the nearest whole number. (Try it!)

Month time units are also different because the `time:difference-between` primitive used to update `time-simulated` and `time-remaining` ignores the year when calculating time differences in months. Hence, the difference between a date in April and a date in May is always 1 month, even if those dates are in different years. Consequently, `time-simulated` and `time-remaining` are not calculated correctly when `time-step-units` is chosen to be `months`.

## THINGS TO TRY

Change the time step units in the chooser and the time step length in the slider, hit `setup` and `step` to see exactly how the time extension works. For example:

* What happens to the date and day of year when leap day arrives?
* How do days and hours advance if the time step is 1.4 weeks? Or 6 minutes?
* How does time advance if the start date is June 17 and the time step is 1 month? Or 1 year?

If you prefer a different format for date and time input (`sim-start-time` and `sim-end-time`), try changing the two `time:create-with-format` statements in `setup` to use your preferred format.

## RELATED MODELS

The NetLogo models library contains other example uses of the time extension, in its Code Examples > Extension Examples section.

## CREDITS AND REFERENCES

This model was drafted by Steve Railsback

(back to the NetLogo User Community Models)