Register to post in forums, or Log in to your existing account
 

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » zMUD General Discussion
Private
Adept


Joined: 10 Jan 2002
Posts: 264
Location: USA

PostPosted: Sun Jun 05, 2005 7:39 pm   

finding minutes between long dates
 
anyone know a way to calculate this?

(Sun Jun 5 15:31:43 2005) - (Wed Jun 1 14:36:01 2005) = ??? minutes
or
(Fr Dec 30 10:00:31 2005) - (Mon Jan 2 9:11:05 2006) = ??? minutes

minutes_uptime = ???

I shoulda payed more attention in math class :P
Reply with quote
nexela
Wizard


Joined: 15 Jan 2002
Posts: 1644
Location: USA

PostPosted: Sun Jun 05, 2005 8:40 pm   
 
Why not just use %ctime which is for connected time in milliseconds.
_________________
Zmud Support Library
Zmud Knowledge Base
Reply with quote
DeReP
Adept


Joined: 14 Jun 2003
Posts: 222
Location: Chile

PostPosted: Sun Jun 05, 2005 11:36 pm   
 
I found an interesting website that does that for you, I'm sure we could come up with an interesting function as well :D
http://www.calendarhome.com/date.shtml
Quote:
# of Days Between...
June 1, 2005
and
June 5, 2005

4 Days
= 96 Hours
= 5760 Minutes
= 345600 Seconds

+60 + 5
Reply with quote
MattLofton
GURU


Joined: 23 Dec 2000
Posts: 4834
Location: USA

PostPosted: Mon Jun 06, 2005 4:19 am   
 
Umm, let's see...

The formula we need to end up with is (Days * 86400) + (Hours * 3600) + (Minutes * 60) + Seconds

However, since the number of days varies every 4 years (every 400 years for years that end in 00) and since there are a varied number of days in each month, we first need to first convert our dates to a Days format. For this, we need to use a 365-day year lookup table:

#case %ismember(%1, "Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec") {Days = 0} {Days = 31} {Days = 59} {Days = 90} {Days = 120} {Days = 151} {Days = 181} {Days = 212} {Days = 243} {Days = 273} {Days = 304} {Days = 334}

Now we test for leapyear and whether we have passed it or not:

#if (%ends(%3,"00")) {LeapYear = %mod(%3,400)} {LeapYear = %mod(%3,4)}
#if ((@Days + %2) > 59) {#noop we are on or past feb 29;#if (@leapyear) {#add Days (%2 + 1)} {#add Days %2}}

At this point, we now have our Date reduced to Days and can resolve our formula:

DateInSeconds = %eval((@Days * 86400) + (%4 * 3600) + (%5 * 60) + %6)

This will convert a date into seconds, allowing you to do something like this to figure out uptime (once you get the #FUNCTION correctly written up):

UptimeInSeconds = DateInSeconds(Month, Day, Year, Hour, Minute, Second) - DateInSeconds(Month, Day, Year, Hour, Minute, Second)
_________________
EDIT: I didn't like my old signature
Reply with quote
DeReP
Adept


Joined: 14 Jun 2003
Posts: 222
Location: Chile

PostPosted: Mon Jun 06, 2005 5:01 pm   
 
The rule for years that have 1 more day is that they are divisible by 4
so you could skip the 400 part and just look if the year is divisible by 4, if not, then its a 365 days year.
Very nice efficient script though.
Reply with quote
Private
Adept


Joined: 10 Jan 2002
Posts: 264
Location: USA

PostPosted: Mon Jun 06, 2005 7:06 pm   
 
nexela: trying to compute between mud uptime and current time... not connection time.
DeReP: it also needs to do the actual time down to minutes, dont care about the accuracy of seconds.

MattLofton, im so glad you posted that days list... i came up with:

#VAR day_of_year {0|31|59|90|120|151|181|212|243|273|304|334}

but wasnt sure if i was correct on it.

I didnt figure seconds... didnt care to be THAT exact.. so i did days*1440

I have the script written now... still doing testing on it, so far it takes:

Since Reboot Since Added
Mob Deaths : 706,560 272,112,958

and 2 time lines:

Aardwolf entered a new age at Wed Jun 1 14:36:01 2005
The system time is Mon Jun 6 14:57:48 2005

i then use a condition 'within' trigger to fire off of system time and see in #SHOWS:

+---------------------------------------------------
| Mobs Killed: 112958
| Mobs Need Killing: 887042
| Aardwolf rebooted: 0y 0m 5d 0h 21m ago.
| Minutes Since Reboot: 7221
| Mobs killed per minute: 97
| Prediction: 6d 8h 24m till next hour of double.
+---------------------------------------------------

like i said the 47 seconds i aint critically worried about as im going by avg kills per minute.

didnt realize how many variables i used...
1 alias (fires the 2 info commands)
3 triggers (captures mob,boot,time info)

and.... FORTY variables :P

i also didnt allow for leap year... so my script will 'break' in 2008 :P

I'm also pretty sure from my math that its gonna break between DEC and JAN... didnt do a IF num_months < 0 calculation.

But anyhoo... i ramble, thanks a bunch your info helped a ton. :)


Last edited by Private on Fri Sep 09, 2005 8:47 am; edited 1 time in total
Reply with quote
Full Throttle
Wanderer


Joined: 07 Dec 2004
Posts: 65

PostPosted: Sat Jun 11, 2005 11:40 am   
 
I would use VBScript for this problem, much simpler.

#alias timediff {#noop VBScript
#mss {MinDiff = DateDiff(~"n~", ~"%1~", ~"%2~")}
#show {Time Difference ~[ %1 ~] ~[ %2 ~] = %mss(MinDiff) minutes}}

Input:

timediff "1/1/2005 12:00:00" "1/1/2005 13:00:00"
timediff "1/1/2005 12:00:00" "1/2/2005 12:00:00"
timediff "6/1/2005 14:36:01" "6/5/2005 15:31:43"
timediff "12/30/2005 10:00:31" "1/2/2006 9:11:05"

Output:

Time Difference [ 1/1/2005 12:00:00 ] [ 1/1/2005 13:00:00 ] = 60 minutes
Time Difference [ 1/1/2005 12:00:00 ] [ 1/2/2005 12:00:00 ] = 1440 minutes
Time Difference [ 6/1/2005 14:36:01 ] [ 6/5/2005 15:31:43 ] = 5815 minutes
Time Difference [ 12/30/2005 10:00:31 ] [ 1/2/2006 9:11:05 ] = 4271 minutes

If VBScript is not an available scripting language on your computer, then you can download Microsoft Windows Script 5.6 here:

http://msdn.microsoft.com/library/default.asp?url=/downloads/list/webdev.asp

You have to check "Allow VBScript" in preferences/script parser within zMUD.
Reply with quote
Full Throttle
Wanderer


Joined: 07 Dec 2004
Posts: 65

PostPosted: Sat Jun 11, 2005 2:45 pm   
 
Code:
#class {SinceReboot}
#var t1 {0} {0}
#var t2 {0} {0}
#var db {0} {0}
#alias time {
  #variable %1 %subregex("%2","(\w+) (\w+) (\d+) (\d+):(\d+):(\d+) (\d+)","%%2/%%3/%%7 %%4:%%5:%%6")
  #addkey db {Jan=1|Feb=2|Mar=3|Apr=4|May=5|Jun=6|Jul=7|Aug=8|Sep=9|Oct=10|Nov=11|Dec=12}
  #loopdb @db {#variable %1 %replace(@{%1},%key,%val)}}
#trigger {^Aardwolf entered a new age at (*)} {
  time t1 "%1"}
#trigger {^The system time is (*)} {
  time t2 "%1"
  #mss {MinDiff = DateDiff(~"n~", ~"@t1~", ~"@t2~")}
  #show {}
  #show {Since Reboot: %mss(MinDiff) minutes}}
#class 0


Input:

#echo {Aardwolf entered a new age at Wed Jun 1 14:36:01 2005}
#echo {The system time is Mon Jun 6 14:57:48 2005}

Output:

Aardwolf entered a new age at Wed Jun 1 14:36:01 2005
The system time is Mon Jun 6 14:57:48 2005

Since Reboot: 7221 minutes
Reply with quote
Private
Adept


Joined: 10 Jan 2002
Posts: 264
Location: USA

PostPosted: Fri Jun 17, 2005 4:32 am   finding minutes between long dates, 7.1x broke it
 
mud output:
Code:

It is 1 o'clock am, Day of the Great Gods, 26th the Month of the Ancient Darkness.
Aardwolf entered a new age at Sat Jun 11 16:37:43 2005

The system time is Fri Jun 17 00:22:19 2005
.


#ALIAS time {#mss {MinDiff = DateDiff(~"n~", ~"%1~", ~"%2~")};min_uptime = %mss(MinDiff)}

Zmud now gives an error:

Code:

Error executing MinDiff = DateDiff("n", "Jun/11/25 16:37:43", "6/17/25 :22:19")
Type mismatch: '[string: "6/17/25"]' (error 13) on line 1, column 1


dunno which version after 7.05a it started, running 7.13 (should be 'a' but doesnt say, diff thread :p) now.

apparently the bit that triggers dotime t2 is not working correctly

EDIT: does the (\d+) pick up 00 correctly...
Fri Jun 17 00:33:35 2005

it appears to be missing in the t2 variable = 6/17/25 :33:35
Reply with quote
Full Throttle
Wanderer


Joined: 07 Dec 2004
Posts: 65

PostPosted: Fri Jun 17, 2005 5:59 am   
 
The replace function in the time alias is removing all the zeros.

I don't know why...

So "10:00:01" would be replace by "1::1".

You can get the script to work correctly if you quote the %key and %val variables in the #loopdb line within the time alias.

#loopdb @db {#variable %1 %replace(@{%1},"%key","%val")}
Reply with quote
nexela
Wizard


Joined: 15 Jan 2002
Posts: 1644
Location: USA

PostPosted: Tue Jul 12, 2005 2:00 am   
 
If its still needed here is a working Aardwolf example 1 var, 1 trigger:p

#VAR Months {Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec}
#TRIGGER "t_uptime" {^Aardwolf entered a new age at %w (%w) (%d) (%x) (%d).} {}
#COND {^The system time is %w (%w) (%d) (%x) (%d)(.)} {
#MSS {uptime = datediff(~"n~", ~"%ismember( %t1, @months)/%t2/%t4 %t3~", ~"%ismember( %1, @months)/%2/%4 %3~")}
#SHOW Uptime is %mss( uptime) minutes

SEEEEE I can be usefull
_________________
Zmud Support Library
Zmud Knowledge Base
Reply with quote
Full Throttle
Wanderer


Joined: 07 Dec 2004
Posts: 65

PostPosted: Thu Jul 14, 2005 2:41 am   
 
Nice job Nexela Smile

Here is my script for Medievia based on Nexela's post:

Code:
#trigger {^   Medievia start time was %w (%w) (%d) (%x) (%d)} {}
#condition {^The current system time is %w (%w) (%d) (%x) (%d)} {
#mss {mindiff = datediff(~"n~",~"%ismember(%t1, {Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec})/%t2/%t4 %t3~",~"%ismember(%1, {Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec})/%2/%4 %3~")}
#substitute {%line ~[ %eval(%mss(mindiff)/60) hour %eval(%mss(mindiff)\60) minute ~]}}


Input:

Medievia start time was Wed Jul 13 06:24:15 2005
The current system time is Wed Jul 13 23:06:14 2005

Output:

Medievia start time was Wed Jul 13 06:24:15 2005
The current system time is Wed Jul 13 23:06:14 2005 [ 16 hour 42 minute ]
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » zMUD General Discussion All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

© 2009 Zugg Software. Hosted by Wolfpaw.net