evennia.utils.gametime

The gametime module handles the global passage of time in the mud.

It also supplies some useful methods to convert between in-mud time and real-world time as well allows to get the total runtime of the server and the current uptime.

class evennia.utils.gametime.TimeScript(*args, **kwargs)[source]

Bases: evennia.scripts.scripts.DefaultScript

Gametime-sensitive script.

at_script_creation()[source]

The script is created.

at_repeat()[source]

Call the callback and reset interval.

exception DoesNotExist

Bases: evennia.scripts.scripts.DefaultScript.DoesNotExist

exception MultipleObjectsReturned

Bases: evennia.scripts.scripts.DefaultScript.MultipleObjectsReturned

path = 'evennia.utils.gametime.TimeScript'
typename = 'TimeScript'
evennia.utils.gametime.runtime()[source]

Get the total runtime of the server since first start (minus downtimes)

Parameters

format (bool, optional) – Format into a time representation.

Returns

time (float or tuple)

The runtime or the same time split up

into time units.

evennia.utils.gametime.server_epoch()[source]

Get the server epoch. We may need to calculate this on the fly.

evennia.utils.gametime.uptime()[source]

Get the current uptime of the server since last reload

Parameters

format (bool, optional) – Format into time representation.

Returns

time (float or tuple)

The uptime or the same time split up

into time units.

evennia.utils.gametime.portal_uptime()[source]

Get the current uptime of the portal.

Returns

time (float) – The uptime of the portal.

evennia.utils.gametime.game_epoch()[source]

Get the game epoch.

evennia.utils.gametime.gametime(absolute=False)[source]

Get the total gametime of the server since first start (minus downtimes)

Parameters

absolute (bool, optional) – Get the absolute game time, including the epoch. This could be converted to an absolute in-game date.

Returns

time (float) – The gametime as a virtual timestamp.

Notes

If one is using a standard calendar, one could convert the unformatted return to a date using Python’s standard datetime module like this: datetime.datetime.fromtimestamp(gametime(absolute=True))

evennia.utils.gametime.real_seconds_until(sec=None, min=None, hour=None, day=None, month=None, year=None)[source]

Return the real seconds until game time.

Parameters
  • sec (int or None) – number of absolute seconds.

  • min (int or None) – number of absolute minutes.

  • hour (int or None) – number of absolute hours.

  • day (int or None) – number of absolute days.

  • month (int or None) – number of absolute months.

  • year (int or None) – number of absolute years.

Returns

The number of real seconds before the given game time is up.

Example

real_seconds_until(hour=5, min=10, sec=0)

If the game time is 5:00, TIME_FACTOR is set to 2 and you ask the number of seconds until it’s 5:10, then this function should return 300 (5 minutes).

evennia.utils.gametime.schedule(callback, repeat=False, sec=None, min=None, hour=None, day=None, month=None, year=None, *args, **kwargs)[source]

Call a callback at a given in-game time.

Parameters
  • callback (function) – The callback function that will be called. Note that the callback must be a module-level function, since the script will be persistent. The callable should be on form callable(*args, **kwargs) where args/kwargs are passed into this schedule.

  • repeat (bool, optional) – Defines if the callback should be called regularly at the specified time.

  • sec (int or None) – Number of absolute game seconds at which to run repeat.

  • min (int or None) – Number of absolute minutes.

  • hour (int or None) – Number of absolute hours.

  • day (int or None) – Number of absolute days.

  • month (int or None) – Number of absolute months.

  • year (int or None) – Number of absolute years.

  • *args – Will be passed into the callable. These must be possible to store in Attributes on the generated scheduling Script.

  • **kwargs

    Will be passed into the callable. These must be possible to store in Attributes on the generated scheduling Script.

Returns

script (Script) – The created Script handling the sceduling.

Examples

schedule(func, min=5, sec=0) # Will call 5 minutes past the next (in-game) hour. schedule(func, hour=2, min=30, sec=0) # Will call the next (in-game) day at 02:30.

evennia.utils.gametime.reset_gametime()[source]

Resets the game time to make it start from the current time. Note that the epoch set by settings.TIME_GAME_EPOCH will still apply.