Skip to content

Instantly share code, notes, and snippets.

@tmedwards
Last active October 2, 2021 00:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tmedwards/94506ca62226be1d273fb920d690d71c to your computer and use it in GitHub Desktop.
Save tmedwards/94506ca62226be1d273fb920d690d71c to your computer and use it in GitHub Desktop.
Date & Time Widgets for the Gregorian Calendar

Date & Time Widgets for the Gregorian Calendar

The widgets use the JavaScript Date object to provide the inner workings of a Gregorian Calendar (a.k.a. Christian/Western calendar).

Set the initial date to the date/time you want and all players should see the same game world dates and times.

Installation

The widgets within the date_time_widgets.txt file (see below) should be pasted into a widget tagged passage. After doing so, the initial game date/time must be set within the setup section. Each of the printing widgets may be customized.

Examples

Printing dates and times:

''Date:'' <<date>>
''Time:'' <<time12h>> (12H) / <<time24h>> (24H)
''Both:'' <<datetime>> (12H)

Advancing time:

/* Adds 5 minutes. */
<<addmins 5>>

/* Adds 5 hours. */
<<addhours 5>>

/* Adds 5 days. */
<<adddays 5>>
/*
Date & Time Widget Setup
*/
<<set
window.GameDays to [
"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
];
window.GameMonths to [
"Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
];
/*
Below we have to use the multi-parameter version of the Date
constructor, rather than the date string version, because the
date string version treats a missing timezone offset as UTC.
While there are ways to determine players' timezone offsets,
so they could be added to a date string, it's more convenient
simply to use the multi-parameter constructor.
The point of this is so that you can simply initialize the game
world clock to whatever date and time you wish without having to
worry about the players' timezone offsets, while still ensuring
that they all see the same game world dates and times.
*/
/* params: year , month(0-based) , day , hour(24H) , minute [, second ] */
$gameDate to new Date(2015, 2, 17, 3, 24); /* e.g. Mar 17, 2015 03:24 */
>>
/*
Date & Time Advancement Widget Definitions
*/
/* Adds the specified number of minutes. */
<<widget "addmins">>\
<<run $gameDate.setMinutes($gameDate.getMinutes() + $args[0])>>\
<</widget>>
/* Adds the specified number of hours. */
<<widget "addhours">>\
<<run $gameDate.setHours($gameDate.getHours() + $args[0])>>\
<</widget>>
/* Adds the specified number of days. */
<<widget "adddays">>\
<<run $gameDate.setHours($gameDate.getHours() + $args[0] * 24)>>\
<</widget>>
/*
Date & Time Printing Widget Definitions
*/
/* Prints the current date ("{weekday} {month} {day}, {year}"). */
<<widget "date">>\
<<print String.format("{0} {1} {2}, {3}",
GameDays[$gameDate.getDay()],
GameMonths[$gameDate.getMonth()],
$gameDate.getDate(),
$gameDate.getFullYear()
)>>\
<</widget>>
/* Prints the current time (12H). */
<<widget "time12hr">>\
<<if $gameDate.getHours() eq 0>>\
12\
<<elseif $gameDate.getHours() gt 12>>\
<<print $gameDate.getHours() - 12>>\
<<else>>\
<<print $gameDate.getHours()>>\
<</if>>:\
<<if $gameDate.getMinutes() lt 10>>0<</if>><<print $gameDate.getMinutes()>> \
<<if $gameDate.getHours() gte 12>>PM<<else>>AM<</if>>\
<</widget>>
/* Prints the current time (24H). */
<<widget "time24hr">>\
<<if $gameDate.getHours() lt 10>>0<</if>><<print $gameDate.getHours()>>:\
<<if $gameDate.getMinutes() lt 10>>0<</if>><<print $gameDate.getMinutes()>>\
<</widget>>
/* Prints the current date and time (12H). */
<<widget "datetime">><<date>> <<time12hr>> (<<time24hr>>)<</widget>>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment