mIRC Home    About    Download    Register    News    Help

Print Thread
Returning week numer back to mirc. #195782 02/03/08 10:40 AM
Joined: Feb 2006
Posts: 97
O
ots654685 Offline OP
Babel fish
OP Offline
Babel fish
O
Joined: Feb 2006
Posts: 97
It's possible to return years/months/days and time back to mirc but how do i convert it in to a week number since there isn't a week option.

/$date(yymmdd)

Re: Returning week numer back to mirc. [Re: ots654685] #195785 02/03/08 11:27 AM
Joined: Jun 2007
Posts: 933
5
5618 Offline
Hoopy frood
Offline
Hoopy frood
5
Joined: Jun 2007
Posts: 933
Well, there's no direct command to return the week number.
One workaround you could use is starting with
Code:
$duration($calc($ctime - $ctime(January 1 $asctime(yyyy) 00:00:00)))

and then round the week number up or down. However, that still leaves you with the problem of in which week Jan 1st falls (week 52 or 1). So yeah, it's not as easy as you'd like, to my knowledge.

Re: Returning week numer back to mirc. [Re: ots654685] #195790 02/03/08 01:57 PM
Joined: Aug 2003
Posts: 144
M
Miguel_A Offline
Vogon poet
Offline
Vogon poet
M
Joined: Aug 2003
Posts: 144
Hi.

Itīs easy you only need to think how you woud do it your self.

Firts you need the check how many time ( in seconds ) has passed between the beguining off the year in question.
Them you need to calc the seconds since the beguinning off the year until today.
After that you need only to calc the seconds for 604800 ( that itīs in seconds the duration off a week)

Code:
alias weeks {
  ;This will return the beguin ctime yearon this case 01/01/08 at 00:00:00 hours
  var %x $ctime( $+( 01/01/, $date(yy)) 0:00:00)
  ;This will calculate the seconds between the beguining off the year until this hours off today
  var %x $calc( $ctime - %x)
  ;This will calculate the nr off weeks, until today
  ;In this example i will use the duration becouse he tell me the week.
  return $gettok( $duration( %x, 1), 1, 32)
}

; You can use always a calc that donīt need the $duration identifier
;Knowing that one week has 604800 seconds them you will divide the total duration until know ( in seconds), and you will obtain the exacle weekīs.
;We use the $int idntifier to return the integer part off the calculation.
return $int( $calc( %x / 604800))


Good luck

Last edited by Miguel_A; 02/03/08 01:58 PM.
Re: Returning week numer back to mirc. [Re: Miguel_A] #195791 02/03/08 02:12 PM
Joined: Jun 2007
Posts: 933
5
5618 Offline
Hoopy frood
Offline
Hoopy frood
5
Joined: Jun 2007
Posts: 933
Yes, and that script won't work since he wants the week number, not the number of weeks passed since Jan 1.
I looked it up and week 1 (ISO standard) is defined as the week containing the first Thursday of the year. With this info you could write a script to calculate the current week depending what day of the week Jan 1 fell on.

Re: Returning week numer back to mirc. [Re: 5618] #195796 02/03/08 03:01 PM
Joined: Aug 2003
Posts: 144
M
Miguel_A Offline
Vogon poet
Offline
Vogon poet
M
Joined: Aug 2003
Posts: 144
The week number off what or since when ?

Re: Returning week numer back to mirc. [Re: ots654685] #195797 02/03/08 03:11 PM
Joined: Jun 2007
Posts: 933
5
5618 Offline
Hoopy frood
Offline
Hoopy frood
5
Joined: Jun 2007
Posts: 933
I tinkered around a bit and came up with this, so far:
Code:
/week {
  var %day.jan.1 = $date($ctime(January 1 $asctime(yyyy) 00:00:00),ddd)
  var %days.expired = $calc(($ctime - $ctime(January 1 $date(yyyy) 00:00:00)) / 86400)
  if (%day.jan.1 = Mon)     { var %days.adjusted = %days.expired }
  elseif (%day.jan.1 = Tue) { var %days.adjusted = $calc(%days.expired + 1) }
  elseif (%day.jan.1 = Wed) { var %days.adjusted = $calc(%days.expired + 2) }
  elseif (%day.jan.1 = Thu) { var %days.adjusted = $calc(%days.expired + 3) }
  elseif (%day.jan.1 = Fri) { var %days.adjusted = $calc(%days.expired - 3) }
  elseif (%day.jan.1 = Sat) { var %days.adjusted = $calc(%days.expired - 2) }
  elseif (%day.jan.1 = Sun) { var %days.adjusted = $calc(%days.expired - 1) }
  echo -agt It is now week: $gettok($calc((%days.adjusted / 7) + 1),1,46)
}


Edit: edited the code to look cleaner, does the same still.

Last edited by 5618; 02/03/08 04:16 PM.
Re: Returning week numer back to mirc. [Re: Miguel_A] #195798 02/03/08 03:20 PM
Joined: Feb 2006
Posts: 97
O
ots654685 Offline OP
Babel fish
OP Offline
Babel fish
O
Joined: Feb 2006
Posts: 97
Originally Posted By: Miguel_A
The week number off what or since when ?
Current week we live in.

@all
Thanks for helping. Didn't expect this large of code but gonna check it out.

Re: Returning week numer back to mirc. [Re: ots654685] #195800 02/03/08 04:03 PM
Joined: Feb 2006
Posts: 546
J
jaytea Offline
Fjord artisan
Offline
Fjord artisan
J
Joined: Feb 2006
Posts: 546
here's a shortened version of the method if you're interested:

Code:
alias week return $ceil($calc((($ctime - $ctime(0:0 $time(1/1/yy))) / 86400 - $findtok(Mon Tue Wed Thu Fri Sat Sun,$time(ddd),32) + 4) / 7))


i wonder if anyone can figure out a shorter way to map $day or $time(ddd) onto an integer? :P


"The only excuse for making a useless script is that one admires it intensely" - Oscar Wilde
Re: Returning week numer back to mirc. [Re: ots654685] #195801 02/03/08 04:10 PM
Joined: Aug 2003
Posts: 144
M
Miguel_A Offline
Vogon poet
Offline
Vogon poet
M
Joined: Aug 2003
Posts: 144
Originally Posted By: ots654685
Originally Posted By: Miguel_A
The week number off what or since when ?
Current week we live in.

@all
Thanks for helping. Didn't expect this large of code but gonna check it out.


Hi.

One week == 7 days

if the 1 off January is on a Tuesday ( like this 2008 year ), one week past only when arrive at the next Tuesday. Not Sunday.

Like i have ask before... what do you want in not how many weeks have past out but how many sundays have past out...

That why i have ask what do you want...

Good luck

Re: Returning week numer back to mirc. [Re: jaytea] #195808 02/03/08 06:15 PM
Joined: Oct 2005
Posts: 1,741
G
genius_at_work Offline
Hoopy frood
Offline
Hoopy frood
G
Joined: Oct 2005
Posts: 1,741
There should be a new type added to $asctime to represent the day of the week as a number (with and without leading 0s) and also, since it is the whole reason for this thread, a new type to represent the week as a number (normal and iso).

D = day of week = 1
DD = day of week = 01

w = non-iso week = 1
ww = non-iso week = 01
W = iso week = 1
WW = iso week = 01


I guess technically, mIRC should support most of the types that are in the PHP date() command, though with different identifiers.


Code:

format character	Description	Example returned values
Day	---	---
d	Day of the month, 2 digits with leading zeros	01 to 31
D	A textual representation of a day, three letters	Mon through Sun
j	Day of the month without leading zeros	1 to 31
l (lowercase 'L')	A full textual representation of the day of the week	Sunday through Saturday
N	ISO-8601 numeric representation of the day of the week (added in PHP 5.1.0)	1 (for Monday) through 7 (for Sunday)
S	English ordinal suffix for the day of the month, 2 characters	st, nd, rd or th. Works well with j 
w	Numeric representation of the day of the week	0 (for Sunday) through 6 (for Saturday)
z	The day of the year (starting from 0)	0 through 365
Week	---	---
W	ISO-8601 week number of year, weeks starting on Monday (added in PHP 4.1.0)	Example: 42 (the 42nd week in the year)
Month	---	---
F	A full textual representation of a month, such as January or March	January through December
m	Numeric representation of a month, with leading zeros	01 through 12
M	A short textual representation of a month, three letters	Jan through Dec
n	Numeric representation of a month, without leading zeros	1 through 12
t	Number of days in the given month	28 through 31
Year	---	---
L	Whether it's a leap year	1 if it is a leap year, 0 otherwise.
o	ISO-8601 year number. This has the same value as Y, except that if the ISO week number (W) belongs to the previous or next year, that year is used instead. (added in PHP 5.1.0)	Examples: 1999 or 2003
Y	A full numeric representation of a year, 4 digits	Examples: 1999 or 2003
y	A two digit representation of a year	Examples: 99 or 03
Time	---	---
a	Lowercase Ante meridiem and Post meridiem	am or pm
A	Uppercase Ante meridiem and Post meridiem	AM or PM
B	Swatch Internet time	000 through 999
g	12-hour format of an hour without leading zeros	1 through 12
G	24-hour format of an hour without leading zeros	0 through 23
h	12-hour format of an hour with leading zeros	01 through 12
H	24-hour format of an hour with leading zeros	00 through 23
i	Minutes with leading zeros	00 to 59
s	Seconds, with leading zeros	00 through 59
u	Milliseconds (added in PHP 5.2.2)	Example: 54321
Timezone	---	---
e	Timezone identifier (added in PHP 5.1.0)	Examples: UTC, GMT, Atlantic/Azores
I (capital i)	Whether or not the date is in daylight saving time	1 if Daylight Saving Time, 0 otherwise.
O	Difference to Greenwich time (GMT) in hours	Example: +0200
P	Difference to Greenwich time (GMT) with colon between hours and minutes (added in PHP 5.1.3)	Example: +02:00
T	Timezone abbreviation	Examples: EST, MDT ...
Z	Timezone offset in seconds. The offset for timezones west of UTC is always negative, and for those east of UTC is always positive.	-43200 through 50400
Full Date/Time	---	---
c	ISO 8601 date (added in PHP 5)	2004-02-12T15:19:21+00:00
r	ŧ RFC 2822 formatted date	Example: Thu, 21 Dec 2000 16:01:07 +0200
U	Seconds since the Unix Epoch (January 1 1970 00:00:00 GMT)	See also time()



http://ca.php.net/manual/en/function.date.php


-genius_at_work