Feature - Implemented time function

I know that there's a way to get KoL date, but if there were some way to get the System Time, or even just Minutes To Rollover without hitting the server each request, that would be awesome.
 

Alhifar

Member
I'm actually half-assedly working on a date/time library for the hell of it. If someone can actually come up with a use for it, I can probably have it finished in a couple of days.
 

heeheehee

Developer
Staff member
Just a heads up, I did post this some time before the addition of KoL date to Mafia, but it's primarily geared toward moon-related functions. Not really relevant to time, since that'd require some way to access the computer's internal clock, which we can't really do. You'd have to use visit_url() in some form unless the devs decide to implement get_time(), which'd presumably return UNIX time.
 

StDoodle

Minion
Yeah, I also made use of visit_url() for getting the time. Script enclosed.
 

Attachments

  • timescrape.ash
    1 KB · Views: 43

Theraze

Active member
Yeah... just looked through HolidayDatabase and there's nothing regarding MS_PER_DAY besides the calendar day and moonphase, I think. Could throw something there, but... would it actually be useful having a guess that's based on your computer's clock instead of reality?
 
KoLtime, computer clock time, either way would work, because you can just adjust for your own computer.

Times based on visit_url() are no more efficient than what I currently have because it requires either constantly accessing the web page (100 times a second can murder your internet) or getting the time once and using wait() to get to the time you want to be at, which means that not much else can go on during that time.
 

Theraze

Active member
So, is this something that people would actually care/use enough for it to get included? I'm sitting on four patches that are 'done' already... lookup command categories, combat delevelling, familiar feasting properly affecting modifiers, and tracking ballroom unlocking. While I like having these myself, it does make it hard to spin up more patches for other people that also aren't going to get implemented. :D
 
Other people using them? I don't know. I can think of a handful of uses that I would be able to throw into my scripts as they already exist, so I'm sure there's got to be a few other people out there that could find them useful in their scripts. The only things I can think of that would depend on time might be chat-style bots. My script is a bot that just sorta hangs around, but I can't use wait() because I need to be able to do other things if certain input is thrown into it, and I want it to check the mail every hour or so. I mean... java has time functions, and they're already in use (mafia chat), just having an ASH way to access that would be simple enough.

Had I any idea how to make a patch for java I'd totally write it myself (though, then, I'd have to re-apply it with every update, yeah?)
 

Theraze

Active member
Would only have to re-apply it if you either revert your code, or changes are made to a region that you have different from the source... So if a new command is added and it happens to be right where your added command is, it might scream, but otherwise, it'll just merge the two together. Else every time someone changed modifiers.txt it would wipe out the 50-100 extra lines I've added for delevelling, and I'd go nuts. :D

Well, if you're willing to self-compile it, I'll make the patch... I'll make it LCD... least common denominator... it'll just return time % MS_PER_DAY. That should return the milliseconds spent that day, and you can make it as accurate (or not) as you want it to be.
 
Last edited:
Okay. Is there like a "patch" directory that just overrides existing mafia stuff? I had assumed it [a patch] would change the actual executable (or would I have to start using the .jar? No biggie)

I can totally compile it myself if you could just tell me where it is that I'm supposed to place the final product. Now, by ms spent that day, do you mean since midnight on my pc or since rollover... or since I logged in?
 

Theraze

Active member
http://wiki.kolmafia.us/index.php?title=Compiling_from_Source

There's the how-tos. To actually patch, you need to start from scratch, jar-wise. The patch modifies the sourcecode. Then, when patches happen to the main source, you update yours, compile again, copy it to whatever folder you run KoLmafia in, and run merrily along.

Testing, but it should be done. To return hours, just divide milliseconds in a day by hours in a day...
Code:
[COLOR=#808000]> ash (gametime_to_int())[/COLOR]
 
Returned: 62984091
 
[COLOR=olive]> ash (gametime_to_int() / (86400000 / 24))[/COLOR]
 
Returned: 17
or, if you want a more complicated timer...
Code:
[COLOR=#808000]> ash print((gametime_to_int() / (86400000 / 24)) + ":" + ((gametime_to_int() / (86400000 / 1440)) % 60))[/COLOR]
 
17:34

To reverse this to display time until rollover, subtract each number from the max, so 23-hours, 59-minutes. As so...
Code:
[COLOR=#808000]> ash print(23 - (gametime_to_int() / (86400000 / 24)) + ":" + (59 - (gametime_to_int() / (86400000 / 1440)) % 60))[/COLOR]
 
6:23

As an alias:
Code:
alias torollover => ashq print("You have " + (23 - (gametime_to_int() / (86400000 / 24))) + ":" + (59 - ((gametime_to_int() / (86400000 / 1440)) % 60)) + " left until rollover happens.")
> torollover

You have 6:17 left until rollover happens.
 
Last edited:
Thank you!
Just to clarify, it returns milliseconds passed since the start of the most recent rollover, correct?

I can devolve it into other time functions from there.

milliseconds in Unix time would have also been acceptable, btw :p But thanks for the extra effort to simplify.
 

Theraze

Active member
Yeah, milliseconds since the last rollover began (officially). This let me just grab the getCalendarDay command and tweak it into returning the raw time instead of dividing it into days. Suppose that getCalendarDay could be set to use this to simplify as well... Eh.

Edit: Verified this works. Attached patch that doesn't duplicate calculation code between the two commands.

Edit: Yeah... it worked, but screwed up the calendar. Working patch is below.
 
Last edited:

StDoodle

Minion
That is pretty nifty, it might be the last push I needed to get off my lazy butt and figure out this whole "using patches" thingy. Maybe. ;)
 

Theraze

Active member
Eh, if you actually care to work through figuring it out, send me private messages. Goes for anyone. :)
 

Theraze

Active member
Sorry about that one... bad passing. I was wondering why I had moxie bonus when it said it should be strength... this patch should be fully fixed up. :)
 

Attachments

  • GametimeToInt.patch
    5.6 KB · Views: 25

morgad

Member
I am using this (based on the timescape.ash file someone else posed earlier)

string tillrollover() {
buffer pg = visit_url("account.php");
matcher m = create_matcher("Currently (?:.+?)(\\d\\d\\\:\\d\\d:\\d\\d)", pg);
if (m.find())
return m.group(1);
return "";
}

print(tillrollover() + " until rollover");
 

Theraze

Active member
I know that there's a way to get KoL date, but if there were some way to get the System Time, or even just Minutes To Rollover without hitting the server each request, that would be awesome.

I am using this (based on the timescape.ash file someone else posed earlier)

Fails based on that it still hits the server on each request... does a visit_url on every call. :(
 

StDoodle

Minion
Yeah, I use timescrape.ash exactly ONCE per ascension, so the visit_url() isn't a big deal... if you're going to use it more than three or four times per day... ugh. Especially if you're hitting the KoL server.
 
Top