mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Jan 2007
Posts: 22
D
Deele Offline OP
Ameglian cow
OP Offline
Ameglian cow
D
Joined: Jan 2007
Posts: 22
I don't know, maybe my calculations are wrong, but mIRC says, that this year, we have 52wks and 1day:
Code:
$duration($calc($ctime(31/12/2008) - $ctime(01/01/2008))) = 52wks 1day

BUT THIS IS INCORRECT! This all messes my trivbot, that uses mirc time to get number of week... This is leap year!
Does mIRC have forgotten about it? or maybe Khaled'n'friends? :P


Deele /SCRIPTWORKS/

LV | ENG | RU
Joined: Jan 2003
Posts: 2,523
Q
Hoopy frood
Offline
Hoopy frood
Q
Joined: Jan 2003
Posts: 2,523
mirc does recognize it's a leap year, you can verify that with
//echo -ag $duration($calc($ctime(31/12/2007) - $ctime(01/01/2007)))

You just have the wrong formula; essentially you're leaving the last day of December out of your calculations. Try this:

$duration($calc($ctime(01/01/2009) - $ctime(01/01/2008)))


/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com
Joined: Jan 2007
Posts: 22
D
Deele Offline OP
Ameglian cow
OP Offline
Ameglian cow
D
Joined: Jan 2007
Posts: 22
Then, maybe you can suggest me an algorythm to calculate weeknumber? Mine is not working at leap year... OR, it shows American standart... but I need europe standart...

Last edited by Deele; 05/02/08 02:00 AM.

Deele /SCRIPTWORKS/

LV | ENG | RU
Joined: Jan 2003
Posts: 2,523
Q
Hoopy frood
Offline
Hoopy frood
Q
Joined: Jan 2003
Posts: 2,523
I'm not sure what you mean. Doesn't
$duration($calc($ctime(01/01/2009) - $ctime(01/01/2008)))
do what you want?


/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com
Joined: Jan 2007
Posts: 22
D
Deele Offline OP
Ameglian cow
OP Offline
Ameglian cow
D
Joined: Jan 2007
Posts: 22
No...
Look at this page... That is what I want...


Deele /SCRIPTWORKS/

LV | ENG | RU
Joined: Oct 2003
Posts: 3,918
A
Hoopy frood
Offline
Hoopy frood
A
Joined: Oct 2003
Posts: 3,918
If that's what you want, it's surely not what you're doing in your above code... the code above has 2 date inputs, the page only takes 1.. that's clear proof that you're performing the wrong calculation right there.

"Week number" is not the same thing as "number of weeks in a year". Europe and USA do indeed have different numbering system for the week number of a year, but that code above is not how you calculate it. If you want to know how, look no further than the JS source of the URL you posted-- you can port that implementation to mIRC.

I don't see how this is a bug-- the code you gave works fine..



- argv[0] on EFnet #mIRC
- "Life is a pointer to an integer without a cast"
Joined: Jan 2007
Posts: 22
D
Deele Offline OP
Ameglian cow
OP Offline
Ameglian cow
D
Joined: Jan 2007
Posts: 22
Sorry, I did not gave you any code that counts weeks for given date smile
Here is my code shorthand:
Code:
alias KN { return $ceil($calc($calc($gettok($duration($calc($ctime($1 $+ / $+ $2 $+ / $+ $3) - $ctime(01/01/ $+ $3)),3),1,58)+24) /168)) }

And for you, to understand it:
extended version:
Code:
alias KN {
  var %now = $ctime($1 $+ / $+ $2 $+ / $+ $3)
  var %1jan = $ctime(01/01/ $+ $3)
  var %period = $calc(%now - %1jan)
  var %periodinhours = $gettok($duration(%period,3),1,58)
  var %periodplusday = %periodinhours + 24
  var %countweeksinperiod = %periodplusday / 168
  return $ceil(%countweeksinperiod)
}

Use of code: $KN(dd,mm,yyyy)

I noticed, this, my called - bug, when tryed to fix this code with addon, that counts days in year, to make script udnerstand, if this is leap year, or not, and depending on that, correct calculation by exact days... And when I counted days, I god realy confused...
Code:
$calc($gettok($duration($calc($ctime(31/12/2008) - $ctime(01/01/2008)),3),1,58)/24)

This code tells, that we have only 365 days this year, BUT, we have 356!
Now, your suggestion made little gray mass in my mind to start moving laugh
Code:
$calc($gettok($duration($calc($ctime(01/01/2009) - $ctime(01/01/2008)),3),1,58)/24)

Now, I will try use this code, to make correction in weeknumber code... Want to help me? laugh

PS: You can move this post to topick, you think is best place for it...

Last edited by Deele; 05/02/08 12:14 PM.

Deele /SCRIPTWORKS/

LV | ENG | RU
Joined: Jan 2007
Posts: 22
D
Deele Offline OP
Ameglian cow
OP Offline
Ameglian cow
D
Joined: Jan 2007
Posts: 22
Fully working week number counter scriptlet:
Input: $weeknum(dd,mm,yyyy)
Output: <weeknumber>
Code:
Code:
alias weeknum { return $ceil($calc($calc($gettok($duration($calc($ctime($1 $+ / $+ $2 $+ / $+ $3) - $ctime(01/01/ $+ $3)),3),1,58)+(($calc($gettok($duration($calc($ctime(31/12/ $+ $3) - $ctime(01/01/ $+ $3)),3),1,58)/24) - 363)*24)) /168)) }

Last edited by Deele; 13/05/08 01:16 PM.

Deele /SCRIPTWORKS/

LV | ENG | RU

Link Copied to Clipboard