mIRC Home    About    Download    Register    News    Help

Print Thread
#213879 11/07/09 12:59 AM
Joined: Feb 2005
Posts: 16
J
jkouzes Offline OP
Pikka bird
OP Offline
Pikka bird
J
Joined: Feb 2005
Posts: 16
I made a script to test for the end of the month but, for some reason it gets stuck, could you gurus look at it a see what I did wrong??? Thanks...

What its suppose to look like:
The Hebrew date is Friday, 18th of Tammuz, 5769
Corresponding civil dates: night of 7/9/2009 & day of 7/10/2009

what it does:
The Hebrew date is Friday, 18th of Tammuz, 5769
Corresponding civil dates: night of 6/31/2008 & day of 7/10/2009
Corresponding civil dates: night of 6/30/2009 & day of 7/10/2009

Script:
on *:TEXT:!hebcal*:#:{
/var
%gyear = $date(yyyy)
%gmonth = $date(m)
%gday = $date(d)
%day = $day
/msg $chan The Hebrew date is %day $+ , $hebdate
/var
; Compute last year
if(%gmonth == 1)&&(%gdate == 1) {
%lyear = $calc($date(yyyy) - 1)
%lmonth = $calc($date(m)-1)
%yday = 31
/msg $chan Corresponding civil dates: night of %lmonth $+ / $+ %yday $+ / $+ %lyear & day of %gmonth $+ / $+ %gday $+ / $+ %gyear }
; Comparing months to April-May(5), june-July(7), Sept-Oct(10), Nov-Dec(12) to set last day of the past month 30 days
elseif((%gday == 1)&&(%gmonth == 5)||(%gmonth == 7)||(%gmonth == 10)||(%gmonth == 12)){
%yday = 30
/msg $chan Corresponding civil dates: night of %lmonth $+ / $+ %yday $+ / $+ %gyear & day of %gmonth $+ / $+ %gday $+ / $+ %gyear }
; Comparing months to Dec-Jan(1), Jan-Feb(2), Mar-Apr(4), May-Jun(6), July-Aug(8), Oct-Nov(11) to set last day of the past month 31 days
elseif((%gday == 1)&&(%gmonth == 2)||(%gmonth == 4)||(%gmonth == 6)||(%gmonth == 8)||(%gmonth == 11)){
%yday = 31
/msg $chan Corresponding civil dates: night of %lmonth $+ / $+ %yday $+ / $+ %gyear & day of %gmonth $+ / $+ %gday $+ / $+ %gyear }
; compute for end of Feb and leap year
elseif((%gday == 1)&&(%gmonth == 3)&&($leap(%gyear) == 1)){
%yday = 28
/msg $chan Corresponding civil dates: night of %lmonth $+ / $+ %yday $+ / $+ %gyear & day of %gmonth $+ / $+ %gday $+ / $+ %gyear }
elseif((%gday == 1)&&(%gmonth == 3)&&($leap(%gyear) == 1)){
%yday =29
/msg $chan Corresponding civil dates: night of %lmonth $+ / $+ %yday $+ / $+ %gyear & day of %gmonth $+ / $+ %gday $+ / $+ %gyear }
else{
%yday = $calc($date(d)-1)
/msg $chan Corresponding civil dates: night of %gmonth $+ / $+ %yday $+ / $+ %gyear & day of %gmonth $+ / $+ %gday $+ / $+ %gyear
%yday = $calc($date(d)-1)
/msg $chan Corresponding civil dates: night of %gmonth $+ / $+ %yday $+ / $+ %gyear & day of %gmonth $+ / $+ %gday $+ / $+ %gyear

Joined: Dec 2008
Posts: 1,515
Hoopy frood
Offline
Hoopy frood
Joined: Dec 2008
Posts: 1,515
Try using this code and see if it's work , first of all you have 2 alias identifiers ($hebdate and $leap) that i don't know what these return , anyway try this :

Code:
ON *:TEXT:!hebcal *:#: {
  var %gyear = $date(yyyy), %gmonth = $date(m), %gday = $date(d), %day = $day
  msg $chan The Hebrew date is $day $+ , $hebdate
  ; Compute last year
  if ((%gmonth == 1) && (%gdate == 1)) {
    set %lyear $calc($date(yyyy) - 1)
    set %lmonth $calc($date(m)-1)
    set %yday 31
    msg $chan Corresponding civil dates: night of %lmonth $+ / $+ %yday $+ / $+ %lyear & day of %gmonth $+ / $+ %gday $+ / $+ %gyear
  }
  ; Comparing months to April-May(5), june-July(7), Sept-Oct(10), Nov-Dec(12) to set last day of the past month 30 days
  elseif ((%gday == 1) && (%gmonth == 5) || (%gmonth == 7) || (%gmonth == 10) || (%gmonth == 12)) {
    set %yday 30
    msg $chan Corresponding civil dates: night of %lmonth $+ / $+ %yday $+ / $+ %gyear & day of %gmonth $+ / $+ %gday $+ / $+ %gyear
  }
  ; Comparing months to Dec-Jan(1), Jan-Feb(2), Mar-Apr(4), May-Jun(6), July-Aug(8), Oct-Nov(11) to set last day of the past month 31 days
  elseif ((%gday == 1) && (%gmonth == 2) || (%gmonth == 4) || (%gmonth == 6) || (%gmonth == 8) || (%gmonth == 11)) {
    set %yday 31
    msg $chan Corresponding civil dates: night of %lmonth $+ / $+ %yday $+ / $+ %gyear & day of %gmonth $+ / $+ %gday $+ / $+ %gyear
  }
  ; compute for end of Feb and leap year
  elseif ((%gday == 1) &&( %gmonth == 3) && ($leap(%gyear) == 1)) {
    set %yday 28
    msg $chan Corresponding civil dates: night of %lmonth $+ / $+ %yday $+ / $+ %gyear & day of %gmonth $+ / $+ %gday $+ / $+ %gyear 
  }
  elseif ((%gday == 1) && (%gmonth == 3) && ($leap(%gyear) == 1)) {
    set %yday 29
    msg $chan Corresponding civil dates: night of %lmonth $+ / $+ %yday $+ / $+ %gyear & day of %gmonth $+ / $+ %gday $+ / $+ %gyear
    set %yday = $calc($date(d)-1)
  }
}


Need Online mIRC help or an mIRC Scripting Freelancer? -> https://irc.chathub.org <-
Joined: Feb 2005
Posts: 16
J
jkouzes Offline OP
Pikka bird
OP Offline
Pikka bird
J
Joined: Feb 2005
Posts: 16
Okay, I tried it, but Rats... It still is stuck showing this:
The Hebrew date is Saturday, 19th of Tammuz, 5769
Corresponding civil dates: night of 6/30/2009 & day of 7/11/2009

Joined: Nov 2006
Posts: 1,559
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Nov 2006
Posts: 1,559
Do you want to calculate the gregorian dates for a hebrew date input, or do you want it the other way arround (check if a new hebrew month will start today / at a date provided by the user)?
I guess the latter as the provided script part does not include code e.g. to create the blue part of "The Hebrew date is Saturday, 19th of Tammuz, 5769".
Given the complex rules of the hebrew calendar, maybe a socket script - to query a conversion website like hebcal.com - can do the trick and save alot of calculations (and the headache caused by attempts to understand/apply all the underlying rules). smile



Edit:
Here's a *rough* socket approach. Maybe it is, maybe it is not what you had in mind... smile You can use both !hebcal and !hebcal <gregorian date>
Code:
on *:text:!hebcal*:#: {
  ; no date given: use current date
  if (!$2) { hebcal $chan $ctime }
  ; valid date given (dd/mm/yy or dd/mm/yyyy or dd.mm.yy etc)
  elseif ($ctime($2-)) { hebcal $chan $v1 }
  ; no valid date given
  else { msg $chan Invalid date. Syntax is "!hebcal" to return the current date or "!hebcal <date>" (e.g: !hebcal $date $+ ) }
}

; alias to open the socket
alias -l hebcal {
  ; parameters passed to the alias: $1=channel and $2=ctime of current/requested date
  if ($2) { 
    ; close socket if it's already open; open socket to hebcal.com, mark socket with the passed parameters for later use
    sockclose hebcal
    sockopen hebcal www.hebcal.com 80
    sockmark hebcal $1-
  }
}

; socket opens
on *:sockopen:hebcal: {
  ; don't proceed if an error occured
  if ($sockerr) { return }
  ; fill $N with $1=dd $2=mm $3=yyyy
  tokenize 47 $asctime($gettok($sock($sockname).mark,2,32),dd/mm/yyyy)
  ; request conversion according to this date
  ; gd=gregorian day=$1   gm=gregorian month=$2   gy=gregorian year=$3
  sockwrite -nt $sockname GET $+(/converter/?gd=,$1,&gm=,$2,&gy=,$3) HTTP/1.1
  sockwrite -nt $sockname HOST: $sock($sockname).addr
  sockwrite -n $sockname $crlf
}

; socket replies
on *:sockread:hebcal: {
  ; put reply in a variable
  sockread %hebcal
  ; the hebrew date is returned twice, for the first time right in the title
  ; check reply line for starting with "<head><title>Hebrew Date Converter -)"
  if ($gettok(%hebcal,1-4,32) == <head><title>Hebrew Date Converter -) {
    var %ctime = $gettok($sock($sockname).mark,2,32)

    ; these variables should allow you to create the desired output
    var %hdate = $gettok($gettok(%hebcal,5-,32),1,60)
    var %chan = $gettok($sock($sockname).mark,1,32)
    var %gdate = $date(%ctime)
    var %gdate-1 = $date($calc(%ctime - $duration(1d)))

    ; output gregorian and hebrew dates to the channel
    msg %chan Hebrew Date for the night of %gdate-1 and %gdate : %hdate

    ; unset variable and close socket
    unset %hebcal
    sockclose $sockname
  }
}


Also note that mIRC reads a date "7/9/09" as 7th of september, not as 9th of july. Formatting the output to month/day/year is no problem with $asctime(<ctimevalue>,mm/dd/yy), but you need to parse the input on your own if it shall be read as month/day/year.

Last edited by Horstl; 11/07/09 08:43 PM.
Joined: Feb 2005
Posts: 16
J
jkouzes Offline OP
Pikka bird
OP Offline
Pikka bird
J
Joined: Feb 2005
Posts: 16
Thanks that works, but...its slow and hmmmm blush I already have a script that does the calculations, its a mirc script conversion and works very well. Which a friend of mine wrote for me, which also displays other information than just the date, it shows allot of daily readings and the Torah potion.

So...Sadly, my sad messy coding is the second part cause I thought it would be nice to have the corresponding date to it, so I added the piss poor part... That is the part that I am trying to get fixed. I suck at writing code.


Joined: Nov 2006
Posts: 1,559
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Nov 2006
Posts: 1,559
Well it was only a wild guess smile
Though, I'm yet not certain what you want to do... Calculate yesterday's greg. date and output this date in mm/dd/yy format, or something apart from it?

As long as the date/time won't get before January 1, 1970, you can let mIRC do the most work for date/time calculations. The trick is to convert your date/time to a numerical "ctime"-integer first so you can calculate easily with the integer. (Have a look at $ctime and $asctime in the helpfile).

Example: get yesterday's date in <day> <mm>/<dd>/<yyyy> format
1) $ctime = Number of seconds since Jan 1, 1970
2) $duration(1d) = Number of seconds a day is made of
3) Therefore: $calc($ctime - $duration(1d)) = a ctime within "yesterday".
4) To convert the calculated value back into a "readable" date format, use $asctime(<ctime integer>,<format>). mIRC will account for leap years etc - you don't have to worry about that.
Code:
; todays and yesterdays day/date (american format):
Today: $day $adate --- Yesterday: $asctime($calc($ctime - $duration(1d)),dddd mm/dd/yyyy)

You could as well create a "custom identifier" (e.g. $yesterdate) and use this identifier like $hebdate in your script:
Code:
alias yesterdate { return $asctime($calc($ctime - $duration(1d)),dddd mm/dd/yyyy) }


Last edited by Horstl; 12/07/09 12:09 PM.
Joined: Feb 2005
Posts: 16
J
jkouzes Offline OP
Pikka bird
OP Offline
Pikka bird
J
Joined: Feb 2005
Posts: 16
Thank YOU! Thank You!!! It works, who would have though just one line could do all the if statement stuff... Thank You.


Link Copied to Clipboard