| View previous topic :: View next topic |
| Author |
Message |
w00f Halfop
Joined: 04 Oct 2006 Posts: 49
|
Posted: Sat Jun 02, 2007 5:15 pm Post subject: Calculate time |
|
|
hey, i have a little prob. I'm trying to calc the "wait time" between "now" and some "date".
The date format is monthname/day/year (%b/%d/%Y).
i.e. date = "Jul/04/2007".
im using clock scan , but since its free-form scan i cant use -format in way to set the expected input. only -gmt and -base options are available.
atm i have this
| Code: |
set waitime [duration [expr [clock scan $date -format {%b/%d/%Y}] - [clock seconds]]]
|
i get this , Tcl error: bad switch "-format": must be -base or -gmt :/
any way to fix this ?
ty in advance. |
|
| Back to top |
|
 |
r0t3n Owner
Joined: 31 May 2005 Posts: 507 Location: UK
|
Posted: Sat Jun 02, 2007 5:30 pm Post subject: |
|
|
Maybe something like this?
On my bot's tcldebug:
| Code: | [22:29:37] <@r0t3n> ?vip? return "[duration [expr {[clock scan 07/06/2007] - [clock seconds]}]]"
[22:29:37] -exotic- » TCL: Return: 4 weeks 5 days 30 minutes 35 seconds - 0.183 ms « |
_________________ r0t3n @ #r0t3n @ Quakenet |
|
| Back to top |
|
 |
w00f Halfop
Joined: 04 Oct 2006 Posts: 49
|
Posted: Sat Jun 02, 2007 5:46 pm Post subject: |
|
|
the problem is the month , if the month was in number format instead of name the code certainly works.
| Code: |
.tcl [duration [expr {[clock scan 07/06/2007] - [clock seconds]}]]
ew : Tcl: 4 weeks 5 days 1 hour 13 minutes 44 seconds
.tcl [duration [expr {[clock scan Jul/06/2007] - [clock seconds]}]]
ew : Tcl: unable to convert date-time string "Jul/06/2007"
|
if i convert the Jul/06/2007 to 07/06/2007 should work. but how i do that ? |
|
| Back to top |
|
 |
nml375 Revered One
Joined: 04 Aug 2006 Posts: 2857
|
Posted: Sat Jun 02, 2007 5:55 pm Post subject: |
|
|
One approach might be "string map". Perhaps not the prettiest solution, but should do the trick. _________________ NML_375, idling at #eggdrop@IrcNET |
|
| Back to top |
|
 |
incith Master

Joined: 23 Apr 2005 Posts: 275 Location: Canada
|
Posted: Sat Jun 02, 2007 7:46 pm Post subject: |
|
|
| Code: | | set date [string map "{Jan} {01} {Feb} {02} {Mar} {03} {Apr} {04} {May} {05} {Jun} {06} {Jul} {07} {Aug} {08} {Sep} {09} {Oct} {10} {Nov} {11} {Dec} {12}" $date] |
Like he said, not the prettiest. _________________ ; Answer a few unanswered posts! |
|
| Back to top |
|
 |
Sir_Fz Revered One

Joined: 27 Apr 2003 Posts: 3793 Location: Lebanon
|
Posted: Sat Jun 02, 2007 8:53 pm Post subject: |
|
|
The mapping is supposed to be a list, so it's better to use:
| Code: | | set date [string map {Jan 01 Feb 02 Mar 03 Apr 04 May 05 Jun 06 Jul 07 Aug 08 Sep 09 Oct 10 Nov 11 Dec 12} $date] |
instead. _________________ Follow me on GitHub
- Opposing
Public Tcl scripts |
|
| Back to top |
|
 |
Sir_Fz Revered One

Joined: 27 Apr 2003 Posts: 3793 Location: Lebanon
|
Posted: Sat Jun 02, 2007 8:59 pm Post subject: Re: Calculate time |
|
|
| w00f wrote: | hey, i have a little prob. I'm trying to calc the "wait time" between "now" and some "date".
The date format is monthname/day/year (%b/%d/%Y).
i.e. date = "Jul/04/2007".
im using clock scan , but since its free-form scan i cant use -format in way to set the expected input. only -gmt and -base options are available.
atm i have this
| Code: |
set waitime [duration [expr [clock scan $date -format {%b/%d/%Y}] - [clock seconds]]]
|
i get this , Tcl error: bad switch "-format": must be -base or -gmt :/
any way to fix this ?
ty in advance. |
The [clock scan] command does not have a -format switch.
Edit: Suggested [clock format] but the [string map] seems to be the only (best) solution. _________________ Follow me on GitHub
- Opposing
Public Tcl scripts |
|
| Back to top |
|
 |
w00f Halfop
Joined: 04 Oct 2006 Posts: 49
|
Posted: Sun Jun 03, 2007 8:51 am Post subject: |
|
|
thanks guys , ill try string map  |
|
| Back to top |
|
 |
AskMe Voice
Joined: 11 Apr 2007 Posts: 23 Location: Canada
|
Posted: Tue Jun 12, 2007 4:43 pm Post subject: |
|
|
| Sir_Fz wrote: | The mapping is supposed to be a list, so it's better to use:
| Code: | | set date [string map {Jan 01 Feb 02 Mar 03 Apr 04 May 05 Jun 06 Jul 07 Aug 08 Sep 09 Oct 10 Nov 11 Dec 12} $date] |
instead. |
i try this one (in french)
| Code: | | set date [string map {Jan 01 Fév 02 Mars 03 Avr 04 Mai 05 Juin 06 Juil 07 Aout 08 Sept 09 Oct 10 Nov 11 Déc 12} $date] |
and i got this error when rehash
| Code: | can't read "date": no such variable
while executing
"string map {Jan 01 Fév 02 Mars 03 Avr 04 Mai 05 Juin 06 Juil 07 Aout 08 Sept 09 Oct 10 Nov 11 Déc 12} $date"
invoked from within
"set date [string map {Jan 01 Fév 02 Mars 03 Avr 04 Mai 05 Juin 06 Juil 07 Aout 08 Sept 09 Oct 10 Nov 11 Déc 12} $date] " |
what i do wrong? |
|
| Back to top |
|
 |
nml375 Revered One
Joined: 04 Aug 2006 Posts: 2857
|
Posted: Tue Jun 12, 2007 4:45 pm Post subject: |
|
|
Post the whole script, as it would seem you've placed that line of code incorrectly... _________________ NML_375, idling at #eggdrop@IrcNET |
|
| Back to top |
|
 |
AskMe Voice
Joined: 11 Apr 2007 Posts: 23 Location: Canada
|
Posted: Tue Jun 12, 2007 5:05 pm Post subject: |
|
|
| Code: | set date [string map {Jan 01 Fév 02 Mars 03 Avr 04 Mai 05 Juin 06 Juil 07 Aout 08 Sept 09 Oct 10 Nov 11 Déc 12} $date]
##################
# Voice database #
##################
proc addvoicedb {nick host hand chan args} {
global sql botnick mysqlink date UCSRegistered
set username [UCS:Registered:IsRegistered $nick]
set hostmask "*!*@[lindex [split $host @] 1]"
mysqlexec $mysqlink "INSERT INTO voice
(nick,username,chan,host,ajouté_le) VALUES ('$nick','$username','$chan','$hostmask','$date')"
putlog "$nick a été ajouté a la liste autovoice avec le username $username"
putserv "NOTICE $nick :Vous etes maintenant ajouté ŕ la liste auto voice sur $chan sous le username $username"
}
|
the whole script i a bit messy but this is the only procedure i use date |
|
| Back to top |
|
 |
nml375 Revered One
Joined: 04 Aug 2006 Posts: 2857
|
Posted: Tue Jun 12, 2007 5:10 pm Post subject: |
|
|
$date is not a predefined variable in globalspace, so you'll have to set it to some value before you attempt to read it.
It would seem to me that you're trying to insert current date/time into a mysql-database; in this case, I'd suggest you use the mysql-macro NOW(). Another option would be to use the "clock format" command.
Be adviced that $date will not automatically be updated to hold current time... _________________ NML_375, idling at #eggdrop@IrcNET |
|
| Back to top |
|
 |
AskMe Voice
Joined: 11 Apr 2007 Posts: 23 Location: Canada
|
Posted: Tue Jun 12, 2007 5:26 pm Post subject: |
|
|
| Quote: | | It would seem to me that you're trying to insert current date/time into a mysql-database |
your right
in fact i use
| Code: | | set date [clock format [clock scan "now"] -format %Y.%m.%d] |
but i try to replace it by the maping of Sir_Fz to have the month listed with a name and not with a number
...
as you can see im a not a pro un tcl  |
|
| Back to top |
|
 |
nml375 Revered One
Joined: 04 Aug 2006 Posts: 2857
|
Posted: Tue Jun 12, 2007 5:36 pm Post subject: |
|
|
Reading the manual page I linked on clock format, it should make it obvious you have no use for that string mapping, as the format used would already print the month in numbers.
Also, executing that code you posted once in globalspace will only result in $date holding the time for that particular moment, and not current date.
A proper example, you'll probably need to modify it to suite your needs:
| Code: | proc addvoicedb {nick host hand chan args} {
global mysqlink UCSRegistered
set username [UCS:Registered:IsRegistered $nick]
set hostmask "*!*@[lindex [split $host @] 1]"
mysqlexec $mysqlink "INSERT INTO voice (nick,username,chan,host,ajouté_le) VALUES ('$nick','$username','$chan','$hostmask',NOW())"
} |
Or
| Code: | proc addvoicedb {nick host hand chan args} {
global mysqlink UCSRegistered
set username [UCS:Registered:IsRegistered $nick]
set hostmask "*!*@[lindex [split $host @] 1]"
mysqlexec $mysqlink "INSERT INTO voice (nick,username,chan,host,ajouté_le) VALUES ('$nick','$username','$chan','$hostmask','[clock [clock seconds] -format "%Y.%m.%d"]')"
} |
_________________ NML_375, idling at #eggdrop@IrcNET |
|
| Back to top |
|
 |
AskMe Voice
Joined: 11 Apr 2007 Posts: 23 Location: Canada
|
Posted: Tue Jun 12, 2007 5:53 pm Post subject: |
|
|
| Quote: | Also, executing that code you posted once in globalspace will only result in $date holding the time for that particular moment, and not current date.
| thanks i didnt know that info
and the link have almost all info i need
| Code: | proc addvoicedb {nick host hand chan args} {
global mysqlink UCSRegistered
set username [UCS:Registered:IsRegistered $nick]
set hostmask "*!*@[lindex [split $host @] 1]"
mysqlexec $mysqlink "INSERT INTO voice (nick,username,chan,host,ajouté_le) VALUES ('$nick','$username','$chan','$hostmask','[clock [clock seconds] -format "%Y.%m.%d"]')"
} | if i want the monthname i have to replace the %m by %b or %B right?
if i want to replace the monthname by the monthname but in french is it possible?
sorry if im not clear but my english is limited..  |
|
| Back to top |
|
 |
|