ID:265148
 
There's really two questions here... one practical, one aesthetic.

I've never really done much with anything aside from world.time, and although I've done some fancy things with that, when I get HRH up permanently, I want to make time proceed on the basis of one real-life week (168 hours) == one game season, regardless of server outs, down time, etc. As of now, there's no night or day system, but I may add a system that formally tracks days as two hour intervals. The main thing I'm looking for is a way to check and see if, in reality according to the host computer, it's (for example) Friday at midnight, and if so, move the seasons along one.

Now, the aesthetic point... following the one week == one season formula, when should I make the change: Friday or Sunday would seem to be the most obvious choices, but actually, I'm aiming at making 9:00 to 11:00 CST or so Friday night be day 42 of each 84-day season, marking it in game with an announcement "It is now Seasonheight!", but that would actually make the season change in the middle of the day Tuesday. Of course, there's advantages to having the season change at a time where it's almost guaranteed the server would be empty.

Anyways, any thoughts on either matter?
Well, I'm pretty sure there's no easy way to do this in BYOND, but here's one way I thought up of:

Have an HTML document. Every 10-50 ticks (doesn't have to be very often) update it with the current time and date (or the time and date on seperate files). I forget the HTML tag for this, but I'm looking it up. Then, run a text parser through it, and you can access your computer's time through BYOND.
In response to Garthor (#1)
Okay, here's the code. It definately isn't pretty, but it's all I could find, edited slightly so that it's only the date and time (no "It is now").

<script language=Javascript1.2>
<!--

var tags_before_clock = ""
var tags_middle_clock = ""
var tags_after_clock = ""

if(navigator.appName == "Netscape") {
document.write('<layer id="clock"></layer><br>');
}

if (navigator.appVersion.indexOf("MSIE") != -1){
document.write('<span id="clock"></span>');
}

DaysofWeek = new Array()
DaysofWeek[0]="Sunday"
DaysofWeek[1]="Monday"
DaysofWeek[2]="Tuesday"
DaysofWeek[3]="Wednesday"
DaysofWeek[4]="Thursday"
DaysofWeek[5]="Friday"
DaysofWeek[6]="Saturday"

Months = new Array()
Months[0]="January"
Months[1]="February"
Months[2]="March"
Months[3]="April"
Months[4]="May"
Months[5]="June"
Months[6]="July"
Months[7]="August"
Months[8]="September"
Months[9]="October"
Months[10]="November"
Months[11]="December"

function upclock(){
var dte = new Date();
var hrs = dte.getHours();
var min = dte.getMinutes();
var sec = dte.getSeconds();
var day = DaysofWeek[dte.getDay()]
var date = dte.getDate()
var month = Months[dte.getMonth()]
var year = dte.getFullYear()

var col = ":";
var spc = " ";
var com = ",";
var apm;

if (date == 1 || date == 21 || date == 31)
{ender = ""}
else
if (date == 2 || date == 22)
{ender = ""}
else
if (date == 3 || date == 23)
{ender = ""}

else
{ender = ""}

if (12 < hrs) {
apm="<font size='-1'>pm</font>";
hrs-=12;
}

else {
apm="<font size='-1'>am</font>";
}

if (hrs == 0) hrs=12;
if (hrs<=9) hrs="0"+hrs;
if (min<=9) min="0"+min;
if (sec<=9) sec="0"+sec;

if(navigator.appName == "Netscape") {
document.clock.document.write(tags_before_clock+hrs+col+min+col+sec+apm+spc+tags_middle_clock+spc+day+com+spc+date+ender+spc+month+com+spc+year+tags_after_clock);
document.clock.document.close();
}

if (navigator.appVersion.indexOf("MSIE") != -1){
clock.innerHTML = tags_before_clock+hrs+col+min+col+sec+apm+spc+tags_middle_clock+spc+day+com+spc+date+ender+spc+month+com+spc+year+tags_after_clock;
}
}

setInterval("upclock()",1000);
//-->
</script>
In response to Garthor (#2)
Thanks for the effort, but I don't see the advantage of doing it externally when BYOND has world.realtime built right into it. Basically, I need some guidance on converting that into hours and days.
In response to Lesbian Assassin (#3)
Something like this?

time()
var
days
seconds
minutes
hours
weeks

seconds = round(world.realtime / 10)
minutes = round(seconds / 60)
seconds = seconds % 60
hours = round(minutes / 60)
minutes = minutes % 60
days = round(hours / 24)
hours = hours % 24
weeks = round(days / 7)
days = days % 7


It should be noted that world.realtime doesn't actually have the resolution to accurately keep track of seconds, and that keeping track of months and years is a real pain, but if you just want to find day of the week this is enough. Apparently Saturday counts as the first day of the week under this scheme, since world.realtime is based on time since 1/1/00.
In response to Lesbian Assassin (#3)
Oh, d'oh, I was thinking of world.realtime as the time the server has been up. No sleep and no food makes Garthor something something. Still, the way I told you is probably easier, at least until you can work on a function to get the date.
In response to Leftley (#4)
Thanks, that's exactly what I need... day of the week, and if it can also tell (more or less) what hour it is, that's a plus.
In response to Garthor (#5)
Garthor wrote:
No sleep and no food makes Garthor something something.

Go crazy? I don't mind if you do.

Wait, that might be an impossibility -- sanity is a toggle state, so you can't turn insane when you're already insane. =)
If you're willing to operate with potential slowdown, you could always rely on "cheating" by using BYOND's time2text() function.

var/real_years = text2num(time2text(world.realtime, "YY"))
var/real_months = text2num(time2text(world.realtime, "MM"))
var/real_days = text2num(time2text(world.realtime, "DD"))
var/real_hours = text2num(time2text(world.realtime, "hh"))
var/real_minutes = text2num(time2text(world.realtime, "mm"))
var/real_seconds = text2num(time2text(world.realtime, "ss"))
In response to Spuzzum (#8)
Not so much... the date doesn't interest me, just the day of the week. If I make the seasons change on monday, it doesn't really matter if it's monday the fifth or monday the twelfth.
In response to Lesbian Assassin (#9)
Lesbian Assassin wrote:
Not so much... the date doesn't interest me, just the day of the week. If I make the seasons change on monday, it doesn't really matter if it's monday the fifth or monday the twelfth.

Ah, then it's a bit more complicated, but not much:

proc/determine_day_of_week()
var/day = time2text(world.realtime, "DDD")
switch(day)
if("Mon") return(1)
if("Tue") return(2)
if("Wed") return(3)
if("Thu") return(4)
if("Fri") return(5)
if("Sat") return(6)
if("Sun") return(7)