Help with a Time System

Hi
I found this Time System in a Thread and it works pretty good I think.

/*
	Date & Time Widget Setup
*/
<<set
	/* This must be set to whatever the initial game date/time should be. */
	$gameDate to new Date("2015-03-17T03:24Z"); /* Must use UTC time. */
>>
<<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"
	];
>>


/*
	Date & Time Advancement Widget Definitions
*/
/* Adds the specified number of minutes. */
<<widget "addmins">>\
<<run $gameDate.setUTCMinutes($gameDate.getUTCMinutes() + $args[0])>>\
<</widget>>

/* Adds the specified number of hours. */
<<widget "addhours">>\
<<run $gameDate.setUTCHours($gameDate.getUTCHours() + $args[0])>>\
<</widget>>

/* Adds the specified number of days. */
<<widget "adddays">>\
<<run $gameDate.setUTCHours($gameDate.getUTCHours() + $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 "time12h">>\
<<if $gameDate.getUTCHours() eq 0>>\
12\
<<elseif $gameDate.getUTCHours() gt 12>>\
<<print $gameDate.getUTCHours() - 12>>\
<<else>>\
<<print $gameDate.getUTCHours()>>\
<</if>>:\
<<if $gameDate.getUTCMinutes() lt 10>>0<</if>><<print $gameDate.getUTCMinutes()>> \
<<if $gameDate.getUTCHours() gte 12>>PM<<else>>AM<</if>>\
<</widget>>

/* Prints the current time (24H). */
<<widget "time24h">>\
<<if $gameDate.getUTCHours() lt 10>>0<</if>><<print $gameDate.getUTCHours()>>:\
<<if $gameDate.getUTCMinutes() lt 10>>0<</if>><<print $gameDate.getUTCMinutes()>>\
<</widget>>

/* Prints the current date and time (12H). */
<<widget "datetime">><<date>> <<time12h>><</widget>>

Now I want to make an Shop Open from 6:00 to 16:00 with using these:

<<if $gameDate.getUTCHours() gte 6 and $gameDate.getUTCHours() lte 16>>Open<<else>>Closed<</if>>

My Problem is now I want to let the Shop only be Open on Monday to Friday from 6 to 16.
It should be closed on the Weekend.

How can I do that ?

You just need to add some code to also check the day of the week using .getUTCDay():

<<if ($gameDate.getUTCHours() >= 6) and ($gameDate.getUTCHours() <= 16) and
	 ($gameDate.getUTCDay() > 0) and ($gameDate.getUTCDay() < 6)>>
	Open
<<else>>
	Closed
<</if>>

(Note: day 0 = Sunday and day 6 = Saturday; line breaks added above for readability)

You might also want to check out the “Time” section of my Twine/SugarCube sample code collection.

Enjoy! :grinning:

Thank you ! Next Time I look first in your Collection! :slightly_smiling_face: