Determine if/which holiday it is

Paragon

Member
How do I determine if it is a holiday today, and if it is a holiday how do i determine which one it is?
 

Catch-22

Active member
Create a map from the information here, then use gameday_to_string() and see if it appears in the map. You can have a secondary map for IRL day holidays (April Fools Day etc.) by using today_to_string() but depending on your computers timezone compared to Arizona (I assume KoL still runs on AZ time) it may not always be accurate.

I think there's also holidays that sometimes happen at the whim of TPTB, good luck with those ;)
 

Paragon

Member
Thanks guys, I was only interested in halloween which, luckly is fairly easy to predict... I just thought that mafia might have had some built in way to do it.
 

Theraze

Active member
Regarding 'normal' occurances, you can just check gameday_to_string() or gameday_to_int() for the specific holiday you want, since it will always be the same. What it misses are the RL holiday exceptions... we just had valentines day by KoL calendar schedule, but will probably have it again in ~2 weeks based on RL calendar.
 

Paragon

Member
Here's a patch that would allow ash and cli access to holiday information

File: KolMafia/src/net/sourceforge/kolmafia/textui/RuntimeLibrary.java
Line 411
Code:
		params = new Type[] {};
		functions.add(new LibraryFunction("today_to_holiday", DataTypes.STRING_TYPE,params));
		
		params = new Type[] {};
		functions.add(new LibraryFunction("tommorrow_to_holiday",DataTypes.STRING_TYPE,params));
		
		params = new Type[] {};
		functions.add(new LibraryFunction("predict_holiday",DataTypes.STRING_TYPE,params));

Line 2181
Code:
	public static Value today_to_holiday(Interpreter interpreter)
	{
		return new Value(HolidayDatabase.getHoliday(false));
	}
	
	public static Value predict_holiday(Interpreter interpreter)
	{
		return new Value(HolidayDatabase.getHoliday(true));
	}
	
	public static Value tommorrow_to_holiday(Interpreter interpreter)
	{
		Date d=new Date();
		Calendar cal = Calendar.getInstance();
		cal.setTime(d);
		cal.add(Calendar.DATE, 1);
		return new Value(HolidayDatabase.getHoliday(cal.getTime(),false));
	}
 

lostcalpolydude

Developer
Staff member
If something like tomorrow_to_holiday() was added, I think it would make more sense to allow an arbitrary offset as a parameter (with a different function name of course, though I'm not sure what a good name would be). I haven't looked at the code though.
 

Paragon

Member
I just put tommorow_to_holiday because it would be useful for log out scripts or last minute preparations for a specific holiday, maybe ensure that you rollover to 200 adv instead of burning more today.

Code:
        params = new Type[]{DataTypes.INT_TYPE};
        functions.add(new LibraryFunction("future_to_holiday",DataTypes.STRING_TYPE,params));
Code:
        public static Value future_to_holiday(Interpreter interpreter, Value days)
    {
        Date d=new Date();
        Calendar cal=Calendar.getInstance();
        cal.setTime(d);
        cal.add(Calendar.DATE, (int)days.intValue());
        return new Value(HolidayDatabase.getHoliday(cal.getTime(),false));
    }
 
Last edited:

StDoodle

Minion
If something like tomorrow_to_holiday() was added, I think it would make more sense to allow an arbitrary offset as a parameter (with a different function name of course, though I'm not sure what a good name would be). I haven't looked at the code though.

I dunno, why not just day_to_holiday() and you could always do day_to_holiday(today_to_string) assuming the format could easily be made identical?

Edit: Nevermind; we still can't go backwards to milliseconds since epoch, so the math part is a PITA... sigh
 
Last edited:

Theraze

Active member
Why not day_to_holiday and gameday_to_int? Leave the heavy lifting for which gameday corresponds with a RL day on the player, since my memory is whispering that mafia uses that int to decide if it's a holiday anyways, so no additional decision-code required. Then players can write/use scripts to convert RL days to game days and everyone lives in a land of eternal holidays. And cake. There is cake there.
 

Paragon

Member
I think the most common use would be today_to_holiday, and tommorow_to_holiday... as those are the only two that have practical in-game/in-run usage... knowing past holidays is not useful gameplay wise, and you can pretty much fully prepare within a day, not to mention that if you want more advanced warning there is predict_holiday... So the current format is most conducive to what I would think is the most common usage, if there was an informational script, or chat bot script that needed to know the holiday of a specific date, they could use datelib, which i am fairly certain has a date difference function... using the date difference and future_to_date would be a pretty strait forward way of getting the holiday on any specific date.
 

Theraze

Active member
If you wanted tomorrow (spelling... it's a killer) you could just do day_to_holiday(gameday_to_int()+1). Today would be day_to_holiday(gameday_to_int()).
 
Top