From 753bd352265e3e552ef7969da849e6b517406173 Mon Sep 17 00:00:00 2001 From: Vincent Le Goff Date: Mon, 13 Feb 2017 20:14:09 -0800 Subject: [PATCH] The time epoch defined in settings can now be 0 (different from None). The convert_gametime contrib now has a simple function to return gametime with units. --- evennia/contrib/convert_gametime.py | 19 +++++++++++++++++++ evennia/utils/gametime.py | 3 ++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/evennia/contrib/convert_gametime.py b/evennia/contrib/convert_gametime.py index 8278d59a4..17520881a 100644 --- a/evennia/contrib/convert_gametime.py +++ b/evennia/contrib/convert_gametime.py @@ -141,6 +141,25 @@ def realtime_to_gametime(secs=0, mins=0, hrs=0, days=0, weeks=0, return time_to_tuple(gtime, *units) return gtime +def custom_gametime(absolute=False): + """ + Return the game time as a tuple of units, as defined in settings. + + Args: + absolute (bool, optional): return the relative or absolute time. + + Returns: + The tuple describing the game time. The length of the tuple + is related to the number of unique units defined in the + settings. By default, the tuple would be (year, month, + week, day, hour, minute, second). + + """ + current = gametime(absolute=absolute) + units = sorted(set(UNITS.values()), reverse=True) + del units[-1] + return time_to_tuple(current, *units) + def real_seconds_until(**kwargs): """ Return the real seconds until game time. diff --git a/evennia/utils/gametime.py b/evennia/utils/gametime.py index 1a6e8ebc6..f550f053f 100644 --- a/evennia/utils/gametime.py +++ b/evennia/utils/gametime.py @@ -81,7 +81,8 @@ def game_epoch(): Get the game epoch. """ - return settings.TIME_GAME_EPOCH or server_epoch() + game_epoch = settings.TIME_GAME_EPOCH + return game_epoch if game_epoch is not None else server_epoch() def gametime(absolute=False):