Return KoL date

Fluxxdog

Active member
Is there an ash function that returns the current KoL date (i.e. Petember 1) at all, let alone a string? The only thing I can find that even remotely does this is the CLI command "moon" and using cli_execute() only returns a true/false value. Tell me I'm not missing something that's obvious. Or better yet, tell me I am and point me in the right direction! The wiki doesn't seem to have anything.
 

Theraze

Active member
today_to_string() work for you?

Also useful... moon_phase() should be the current moon phase as an int and moon_light() should return the light amount as an int. Both useful if you're planning out those items and familiars.
 

Fluxxdog

Active member
Nope, today_to_string() only returns the date on your computer, not the actual KoL date (such as Petember 1). The KOL date is the same for me in the US and someone in Russia, where time zone differences can easily return different real world dates.
 

StDoodle

Minion
Since today_to_string() gives the real-life date, it won't be useful (at all, unless coupled with a daily preference).
 

Theraze

Active member
Depressing... I'll go back to the code to search more. :) It's probably somewhere in there... whether or not it has some easy call might be another thing. :)
 

Fluxxdog

Active member
Power to ya! I have no idea where to begin. Mafia should be storing it internally somewhere, otherwise how would it know the KoL date? And if it computes it, there has to be a value somewhere.
 

Theraze

Active member
Can't patch the jar, need to go from clean source. http://wiki.kolmafia.us/index.php?title=Compiling_from_Source will explain how to compile from source in either *nix or Windows. After you've got the clean code, you just right-click the folder and Apply Patch. Compile with Ant, and after you've compiled, copy the KoLmafia.jar file from the dist folder into your regular KoLmafia folder. I overwrite my KoLmafia-latest.jar file, so I can still just run my KoL.bat file. :)
 

Fluxxdog

Active member
Well, I have stuff to compile like THAT already set up on my Linux box. Should be easy as pie. Thanks!

Edit: I just realized with all the cooking changes that were just made, I should probably just wait until some commits it as it will be very hectic otherwise. We're probably going to be seeing at least a few updates per day.

Edit: Strike that, I had to try it out. I mean, Theraze went through the trouble, least I could do was test it. I put my results in the Feature thread with the patch. Results: Success! Thanks!
 
Last edited:

mredge73

Member
Maybe unrelated but I have included some time functions in my function support scripts.
These use the time stamp from unixtimestamp.com and you could probably adjust it to display any time zone that you wish.
Minutes until rollover parses Kol charpane.php

I stole these from Alifar:
Code:
//Returns how many minutes to rollover
//$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
int MinutesToRollover()
{
//get the html source
string source = visit_url("charpane.php");

//the start of the rollover var
int ROS = index_of( source, "var rollover = " ) + length( "var rollover = " );
//the end of the rollover var
int ROE = index_of( source, ";", ROS );
//the start of the rightnow var
int RNS = index_of( source, "var rightnow = " ) + length( "var rightnow = " );
//the end of the rightnow var
int RNE = index_of( source, ";", RNS );
//the start of the rightnow var

//extract the string containing the number part of the start of rollover
string rollover = substring(source, ROS, ROE);
//extract the string containing the number part of kol's version of rightnow
string rightnow = substring(source, RNS, RNE);

return ( to_int( rollover ) - to_int( rightnow ) ) / 60;
}  

// Get-Time by Alifar, EST none daylight savings time, rollover occurs at 23:30
//$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
 string get_time()
{
    int day_sec = 86400;
    int hour_sec = 3600;
    int minute_sec = 60;
    
    buffer emptybuffer;
    buffer timestamp_site = visit_url( "http://www.unixtimestamp.com/index.php" ); ## The sidepane has a timestamp in it, but it doesn't seem to update correctly.
    if(timestamp_site == emptybuffer)    return "Timestamp Unavailable At This Time:(";
    int rightnow = index_of( timestamp_site , "<font color=" );
    string timestamp = substring( timestamp_site , rightnow + 22 , rightnow + 32 );
    int timestamp_int = timestamp.to_int();
    
    int sec_since_midnight = timestamp_int % day_sec;
    hour = ( ( sec_since_midnight - sec_since_midnight % hour_sec ) / hour_sec ) - 5;
    if( hour < 0 )
    {
        hour = hour + 24;
    }
    sec_since_midnight = sec_since_midnight % hour_sec;
    minute = ( ( sec_since_midnight - sec_since_midnight % minute_sec ) / minute_sec );
    second = sec_since_midnight % minute_sec;
    
    string minute_string = minute.to_string();
    string second_string = second.to_string();
    
    if( minute < 10 )
    {
        minute_string = "0" + minute.to_string();
    }
    if( second < 10 )
    {
        second_string = "0" + second.to_string();
    }
    
    string time = hour + ":" + minute_string + ":" + second_string;
    return time;
} 

string get_time(int seconds)
{
    int day_sec = 86400;
    int hour_sec = 3600;
    int minute_sec = 60;
    
    int timestamp_int = seconds;
    
    int sec_since_midnight = timestamp_int % day_sec;
    hour = ( ( sec_since_midnight - sec_since_midnight % hour_sec ) / hour_sec ) - 5;
    if( hour < 0 )
    {
        hour = hour + 24;
    }
    sec_since_midnight = sec_since_midnight % hour_sec;
    minute = ( ( sec_since_midnight - sec_since_midnight % minute_sec ) / minute_sec );
    second = sec_since_midnight % minute_sec;
    
    string minute_string = minute.to_string();
    string second_string = second.to_string();
    
    if( minute < 10 )
    {
        minute_string = "0" + minute.to_string();
    }
    if( second < 10 )
    {
        second_string = "0" + second.to_string();
    }
    
    string time = hour + ":" + minute_string + ":" + second_string;
    return time;
} 

//Return Hour
int get_hour()
{
    get_time();
    return hour;
}

//Return Minute
int get_minute()
{
    get_time();
    return minute;
}


//returns int for the day of the week
// 0 = Sunday
// 1 = Monday
// 2 = Tuesday
// 3 = Wednesday
// 4 = Thursday
// 5 = Friday
// 6 = Saturday
//$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
int day_of_week( )
{
    string date = today_to_string();
    int c = substring(date,0,2).to_int();
    int y = substring(date,2,4).to_int();
    int m = substring(date,4,6).to_int();
    int d = substring(date, 6, 8 ).to_int();
    if( m<3 ) //for Zeller's Rule march is the first month and febuary is last.
    {
        m=m+10;
        y=y-1;
    }
    else m=m-2;
    int temp1 = ( ( ( 13*m ) -1 ) /5 );
    int temp2 = (y/4);
    int temp3 = (C/4);
    int f = d + temp1 + y + temp2 + temp3 - (2*C);
    if ( f < 0 ){return (f % 7) + 7;}
    return f % 7;
}

//Return string for the day of the Week
string Day()
{
    switch (day_of_week( ))
    {
    case 0:
        return "Sunday";
    case 1:
        return "Monday";
    case 2: 
        return "Tuesday";
    case 3:
        return "Wednesday";
    case 4: 
        return "Thursday";
    case 5:
        return "Friday";
    case 6:
        return "Saturday";
    }
    return "";
}
(This code may require a few global constants to be initialized, it is just an excerpt from my function script)
 

Theraze

Active member
Made another patch on the feature board for gameday_to_int() so you can see which rollover (with % 96) you're currently on. That should be even easier for internal script checks.
 
Top