egghelp.org community Forum Index
[ egghelp.org home | forum home ]
egghelp.org community
Discussion of eggdrop bots, shell accounts and tcl scripts.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Find date of second thursday of month
Goto page Previous  1, 2
 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help
View previous topic :: View next topic  
Author Message
Jagg
Halfop


Joined: 24 Jan 2004
Posts: 53

PostPosted: Tue Mar 08, 2011 6:46 am    Post subject: Reply with quote

@caesar i think that is not that simple... already tried this of course.

but
Code:
if {[catch {set datevalue [clock scan $date]}]} {return e8}

clock scan only work with english monthnames!?
see
Code:
% set datevalue [clock scan 8-march-2011]
1299538800
% set datevalue [clock scan 8-märz-2011]
unable to convert date-time string "8-märz-2011"

and
Code:
if {![string equal -nocase [clock format $datevalue -format %B] $monthname]}

gives me always "0" on none english monthnames like e.g. march ("märz" isn't equal to "march") because above code returns the german monthname
Code:
% clock format 1299538800 -format %B
März
Back to top
View user's profile Send private message
arfer
Master


Joined: 26 Nov 2004
Posts: 436
Location: Manchester, UK

PostPosted: Tue Mar 08, 2011 8:20 am    Post subject: Reply with quote

I think this problem is likely to be as a result of server/eggdrop language settings rather than timezone, since a timezone will often encompass several countries/languages.

The best solution would be to think about a rewrite of the script to deal with day and month numbers, mapping the numbers to names or names to numbers wherever required. I'll give it some thought but it would obviously be a pretty major rewrite.
_________________
I must have had nothing to do
Back to top
View user's profile Send private message
arfer
Master


Joined: 26 Nov 2004
Posts: 436
Location: Manchester, UK

PostPosted: Tue Mar 08, 2011 10:02 am    Post subject: Reply with quote

Jagg, please give the following script a thorough testing on your system. Input to the command !finddate is the same (English). Output is English.

[13:57] <@arfer> !finddate sunday december 2010 5
[13:57] <osmosis> cannot find 5 Sunday's in December 2010
[13:57] <@arfer> !finddate wednesday december 2010 5
[13:57] <osmosis> Wednesday 29 December 2010

I have done brief tests with both Tcl 8.4/Eggdrop and Tcl 8.5/Windrop but I do not have access to alternative server language settings.

Hopefully it will now work for any internal language settings. Ensure you restart rather than rehash because of the many changes to the code.

Code:

set vFinddateVersion 11.03.08.14.01

bind PUB - !finddate pPubFinddate

proc pPubFinddate {nick uhost hand chan text} {
    set vars [split $text]
    if {[llength $vars] == 4} {
        set day [lindex $vars 0]; set month [lindex $vars 1]; set year [lindex $vars 2]; set number [lindex $vars 3]
        switch -- [set date [pParseFinddate $day $month $year $number]] {
            e1 {putserv "PRIVMSG $chan :invalid or misspelt full day name"}
            e2 {putserv "PRIVMSG $chan :invalid or misspelt full month name"}
            e3 {putserv "PRIVMSG $chan :year value was not an integer"}
            e4 {putserv "PRIVMSG $chan :year value was not the 4 digits expected"}
            e5 {putserv "PRIVMSG $chan :year value was outside the range 1971 through 2037"}
            e6 {putserv "PRIVMSG $chan :number value was not an integer"}
            e7 {putserv "PRIVMSG $chan :number value was outside the range 1 through 5"}
            e8 {putserv "PRIVMSG $chan :cannot find $number [string totitle ${day}'s] in [string totitle $month] $year"}
            default {putserv "PRIVMSG $chan :$date"}
        }
    } else {putserv "PRIVMSG $chan :correct syntax is !finddate <day> <month> <year> <number>"}
    return 0
}

proc pParseFinddate {day month year number} {
    set dayname [string tolower $day]
    set monthname [string tolower $month]
    if {[lsearch -exact {sunday monday tuesday wednesday thursday friday saturday} $dayname] == -1} {return e1}
    if {[lsearch -exact {january february march april may june july august september october november december} $monthname] == -1} {return e2}
    if {![string is integer -strict $year]} {return e3}
    if {[string length $year] != 4} {return e4}
    if {($year < 1971) || ($year > 2037)} {return e5}
    if {![string is integer -strict $number]} {return e6}
    if {($number < 1) || ($number > 5)} {return e7}
    set daynumber [pMappingFinddate $dayname 1]
    set monthnumber [pMappingFinddate $monthname 2]
    set target 1
    for {set loop 1} {$loop <= 32} {incr loop} {
        set date "$year-$monthnumber-[format %02i $loop]"
        if {[catch {set datevalue [clock scan $date]}]} {return e8}
        if {![string equal [clock format $datevalue -format %m] $monthnumber]} {return e8}
        if {[string equal [clock format $datevalue -format %u] $daynumber]} {
            if {[string equal $target $number]} {
                set rday [pMappingFinddate [clock format $datevalue -format %u] 3]
                set rdate [clock format $datevalue -format %d]
                set rmonth [pMappingFinddate [clock format $datevalue -format %m] 4]
                set ryear [clock format $datevalue -format %Y]
                return "$rday $rdate $rmonth $ryear"
            } else {incr target}
        }
    }
    return 0
}

proc pMappingFinddate {input type} {
    switch -- $type {
        1 {set output [string map -nocase {monday 1 tuesday 2 wednesday 3 thursday 4 friday 5 saturday 6 sunday 7} $input]}
        2 {set output [string map -nocase {january 01 february 02 march 03 april 04 may 05 june 06 july 07 august 08 september 09 october 10 november 11 december 12} $input]}
        3 {set output [string map {1 Monday 2 Tuesday 3 Wednesday 4 Thursday 5 Friday 6 Saturday 7 Sunday} $input]}
        4 {set output [string map {01 January 02 February 03 March 04 April 05 May 06 June 07 July 08 August 09 September 10 October 11 November 12 December} $input]}
        default {}
    }
    return $output
}

putlog "finddate.tcl version $vFinddateVersion loaded"

# eof

_________________
I must have had nothing to do
Back to top
View user's profile Send private message
Jagg
Halfop


Joined: 24 Jan 2004
Posts: 53

PostPosted: Tue Mar 08, 2011 10:29 am    Post subject: Reply with quote

@arfer
...looks really good here now on my CET server! THANKS!!!
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help All times are GMT - 4 Hours
Goto page Previous  1, 2
Page 2 of 2

 
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


Forum hosting provided by Reverse.net

Powered by phpBB © 2001, 2005 phpBB Group
subGreen style by ktauber