For Programmers: Free Programming Magazines  


Home > Archive > Tcl > December 2004 > Having trouble using [clock scan] on Sat Jan 1 2005









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Having trouble using [clock scan] on Sat Jan 1 2005
phillip.s.powell@gmail.com

2004-12-29, 3:59 pm

I have a [clock scan] that calculates a date of Sat, Jan 1 2005 for a
particular function that should display on content on that date. Every
other day, past or future, displays fine, however, Jan 1, 2005 never
displays specifically on that date alone

The timestamp: 1104555600
Please help, this is very time-sensitive!

Phil

Roy Terry

2004-12-29, 3:59 pm

<phillip.s.powell@gmail.com> wrote in message
news:1104338635.495076.100710@f14g2000cwb.googlegroups.com...
> I have a [clock scan] that calculates a date of Sat, Jan 1 2005 for a
> particular function that should display on content on that date. Every
> other day, past or future, displays fine, however, Jan 1, 2005 never
> displays specifically on that date alone
>
> The timestamp: 1104555600
> Please help, this is very time-sensitive!
>
> Phil
>


Here's what I get on Windows 2000 with
Tcl 8.4.6 in PST time zone

(56 % clock format [clock scan "jan 1, 2005"]
Sat Jan 01 12:00:00 AM Pacific Standard Time 2005
57 % clock scan "jan 1, 2005"
1104566400
58 % clock format 1104555600
Fri Dec 31 9:00:00 PM Pacific Standard Time 2004

Notice that my system considers you seconds value
to be 3 hours before midnight.

Better post more detail about your system, timezone,
Tcl version, etc. And the exact Tcl code you are running.


phillip.s.powell@gmail.com

2004-12-30, 8:57 pm

Thanx, I am running FreeBSD Unix remotely on a server in the Eastern
Time Zone, using TCL version 8.4.6

Sorry for the code dump but this is literally the entire block of code.
The offense line is

expected integer but got "Vincent Van Voltenberg once sang in what
band?"
while executing
"incr maxTriviaID"
invoked from within
"if {$hasPassedTrivia} {
# CALCULATE MAX XML ROW ID AND MAX XML ROW GROUP TRIVIA ID
set maxID [XML_MAXID $triviaAttrs]
if {[string length $maxID]..."
(file "val_cma/trivia.tcl" line 59)

Here is the code:



proc CALCULATE_EXPDATE {} {

#--------------------------------------------------------------------------------------------------------------------
# This proc will calculate the trivia expiration date to this coming
Saturday
#
# If today is Saturday then it returns today
#
# Written by Phil Powell on 6/24/2003 after the Big Trivia Crash of
2003!

#--------------------------------------------------------------------------------------------------------------------
set myTime [clock scan "12:00" -gmt 1]
set myWNumber [clock format $myTime -format "%w"]
return [expr {$myTime + ((6 - $myWNumber) * 86400)}]
}

proc CALCULATE_XML_EXPDATE {triviaAttrs triviaAttrCount
hasPassedTrivia} {
set midnightNow [clock scan [clock format [clock scan now] -format
"%m/%d/%Y"]]
set expDate [lindex $triviaAttrs [expr {[lsearch $triviaAttrs
{expDate}] + 1 + ($triviaAttrCount * (([llength $triviaAttrs] /
$triviaAttrCount) - 1))}]]
set expDate [clock scan [clock format $expDate -format "%m/%d/%Y"]];
# ROUND FOUND EXPDATE IN XML GROUP TO MIDNIGHT
if {$hasPassedTrivia} {
incr expDate [expr {7 * 86400}]
while {$expDate <= $midnightNow} {incr expDate [expr {7 * 86400}]; #
INCREASE BY ONE WEEK}
}
return $expDate
}


append blah "<p>
<b>Trivia CMA</b><p>
"

source xml_procs.tcl
source tcl_string_tools.tcl
source vignette_procs.tcl

#--------------------------
# Var Initialization Block
#--------------------------
set triviaFile [file join $env(DOCUMENT_ROOT) xml trivia]
set triviaAttrs [XML_GET_ALL_ELEMENT_ATTRS $triviaFile entry]
set triviaAttrCount [XML_GET_ELEMENT_ATTR_COUNT $triviaAttrs]

set qs {?hasPassedCookie=1&menuItem=trivia}
set errorMsg {}

lappend booleanVars showTriviaResults hasPassedTrivia correctAnswerID
lappend triviaVars question
for {set i 1} {$i <= 5} {incr i} {
lappend triviaVars answer$i
}
set triviaVars [concat $booleanVars $triviaVars]

foreach var $triviaVars {
if {[catch {cgi_import $var} trash] && [lsearch -exact $booleanVars
$var] >= 0} {
set $var 0
} elseif {[catch {cgi_import $var} trash]} {
set $var {}
}
}

if {$hasPassedTrivia} {
# CALCULATE MAX XML ROW ID AND MAX XML ROW GROUP TRIVIA ID
set maxID [XML_MAXID $triviaAttrs]
if {[string length $maxID] == 0 || $maxID == 0} {
set maxID 1
set maxTriviaID 1
} else {
set maxTriviaID [lindex $triviaAttrs [expr {[lsearch $triviaAttrs
{triviaID}] + 1 + ($triviaAttrCount * (([llength $triviaAttrs] /
$triviaAttrCount) - 1))}]]
incr maxTriviaID; incr maxID
}
}

# CALCULATE THE NEXT EXP DATE IF YOU ARE ENTERING A NEW TRIVIA OR
RETRIEVE THE MOST CURRENT EXT DATE IF VIEWING RESULTS

set midnightNow [clock scan [clock format [clock scan now] -format
"%m/%d/%Y"]]
if {[string length $triviaAttrs] == 0} {
set expDate [CALCULATE_EXPDATE]; # DEFAULT TO THIS COMING SATURDAY
} else {
# ADVANCED DATE FROM MAX TRIVIA ID XML GROUP ROW AND INCREASE TO
FIRST FUTURE DATE
set expDate [CALCULATE_XML_EXPDATE $triviaAttrs $triviaAttrCount
$hasPassedTrivia]
if {$showTriviaResults} {
set rowIndex [expr {[llength $triviaAttrs] / $triviaAttrCount}]
while {$expDate > [CALCULATE_EXPDATE] && $rowIndex > 0} {
set expDate [lindex $triviaAttrs [expr {[lsearch $triviaAttrs
{expDate}] + (($rowIndex - 1) * $triviaAttrCount) + 1}]]
set expDate [clock scan [clock format $expDate -format "%m/%d/%Y"]]
incr rowIndex -1
}
}
}


if {$showTriviaResults} {
set trivResultsFile [file join $env(DOCUMENT_ROOT) xml triviaresults]
set trivResultsAttrs [XML_GET_ALL_ELEMENT_ATTRS $trivResultsFile
entry]
set trivResultsAttrCount [XML_GET_ELEMENT_ATTR_COUNT
$trivResultsAttrs]
}


#---END OF VAR INITIALIZATION
BLOCK-----------------------------------------------------------------------


#------------------------------
# Server-Side Validation Block
#------------------------------


if {$hasPassedTrivia && [string length $question] == 0} {
set hasPassedTrivia 0
append errorMsg "$font<font color=cc0000><li>Please enter a trivia
question</li></font></font><p>"
}

if {$hasPassedTrivia && ([string length $correctAnswerID] == 0 ||
$correctAnswerID == 0)} {
set hasPassedTrivia 0
append errorMsg "$font<font color=cc0000><li>Please indicate which
trivia answer is correct</li></font></font><p>"
}

if {$hasPassedTrivia} {
set hasFoundAnswer 0
for {set i 1} {$i <= 5} {incr i} {
if {[string length [set answer$i]] > 0} {
set hasFoundAnswer 1
break
}
}
if {!$hasFoundAnswer} {
set hasPassedTrivia 0
append errorMsg "$font<font color=cc0000><li>Please enter at least
one trivia answer</li></font></font><p>"
}
}

if {$hasPassedTrivia} {
SQUASH_ANSWERS answer 5; # USE THE GLOBAL "SQUASH_ANSWERS" PROC IN
TCL_STRING_TOOLS HERE AND IN POLLS!
for {set i 1} {$i <= 5} {incr i} {
if {$i == $correctAnswerID && [string length [set answer$i]] == 0} {
set hasPassedTrivia 0
append errorMsg "$font<font color=cc0000><li>You must pick an
existing correct trivia answer</li></font></font><p>"
break
}
}
}

#---END OF SERVER-SIDE VALIDATION
BLOCK-----------------------------------------------------------------------------------

#-------------------------------------------------
# HTML Display and XML Row Group Submittal Block
#-------------------------------------------------

if {$hasPassedTrivia} {
for {set i 1} {$i <= 5} {incr i} {
append answerBlah "
Answer #$i: [set answer$i]"
if {[string equal $i $correctAnswerID]} {
append answerBlah "<font color=000099>&lt;-- Correct Answer</font>"
}
append answerBlah <br>
if {[string length [set answer$i]] > 0 && ![string equal [set
answer$i] "null"]} {
if {$showTriviaResults} {
# ADVANCED DATE FROM MAX TRIVIA ID XML GROUP ROW AND INCREASE TO
FIRST FUTURE DATE
set newExpDate [CALCULATE_XML_EXPDATE $triviaAttrs
$triviaAttrCount $hasPassedTrivia]
} else {
set newExpDate $expDate
}
lappend newTriviaAttrs id $maxID triviaID $maxTriviaID question
"[XML_CLEANUP_ATTRIBUTE $question]" answerID $i
lappend newTriviaAttrs correctAnswerID $correctAnswerID answer
"[XML_CLEANUP_ATTRIBUTE [set answer$i]]" expDate $newExpDate
set results [XML_WRITE_BY_PARSE $triviaFile entry trivia
$newTriviaAttrs]
incr maxID
}
set newTriviaAttrs {}
}
append blah "
New Trivia added: <font color=cc0000>$question</font><p>
$answerBlah<p>
This trivia will expire on <b>[clock format $newExpDate -format "%a,
%b %d, %Y"]</b>
"

}

append blah {

<script>

function isValidTriviaForm() {
if (document.triviaForm.question.value == '') {
alert('Please enter a trivia question');
document.triviaForm.question.focus();
return false;
} else {
var hasNoAnswers = true;
var hasNotCheckedAnyAnswer = true;
var hasNotCheckedBesideAnswer = true;
for (i = 1; i <= 5; i++) {
val = eval('document.triviaForm.answer' + i + '.value');
if (val != '' && val != 'null' && val != null) {
hasNoAnswers = false;
}
if (document.triviaForm.correctAnswerID[i-1].checked) {
hasNotCheckedAnyAnswer = false;
}
if (val != '' && val != 'null' && val != null &&
document.triviaForm.correctAnswerID[i-1].checked
) {
hasNotCheckedBesideAnswer = false;
}
}
if (hasNoAnswers) {
alert('Please enter at least one answer');
document.triviaForm.answer1.focus();
return false;
} else if (hasNotCheckedAnyAnswer) {
alert('You must select an answer as the correct answer');
return false;
} else if (hasNotCheckedBesideAnswer) {
alert('You must select an existing answer as the correct answer');
return false;
}
}
}

</script>

<form name=triviaForm method=get action=/cma/index.php
onSubmit = "return isValidTriviaForm()">
<table border=0 width=100%>
}

if {[string length $errorMsg] > 0} {
append blah "
<tr>
<td colspan=4>$errorMsg</td>
</tr>
"
}

# YOU MUST RESET INTO A NEW VARIABLE THE NEXT EXP DATE IF
showTriviaResults IS TRUE OTHERWISE LEAVE ALONE FOR DISPLAY ACCURACY
if {$showTriviaResults} {
set varningExpDate [CALCULATE_XML_EXPDATE $triviaAttrs
$triviaAttrCount $hasPassedTrivia]
} else {
set varningExpDate $expDate
}

if {[expr {$varningExpDate - [clock scan now]}] <= [expr {86400 * 3}]
&& [expr {$varningExpDate - $midnightNow}] >= 0} {
# Less than 3 days left until most recent trivia question expires
# Remind admin to put in a new one
append blah "
<tr>
<td colspan=4>$font<font color=cc0000>VARNING!</font> Your most
recent
trivia question is about to expire on <font color=cc0000>[clock
format $varningExpDate -format "%a %b %d, %Y"]</font>! Please enter
more soon!
</td>
</tr>
"
}

append blah "
<tr>
<td colspan=2>${font}Trivia Question:</td>
<td colspan=2><input name=question size=50 maxlength=255></td>
</tr>
"
for {set i 1} {$i <= 5} {incr i} {
append blah "
<tr>
<td align=right>${smFont}Correct?</font></b></td>
<td><input type=radio name=correctAnswerID value=$i></td>
<td>${font}Answer #$i: </td>
<td><input name=answer$i size=50 maxlength=75></td>
</tr>
"
}

append blah "
<input type=hidden name=hasPassedTrivia value=1>
<input type=hidden name=hasPassedCookie value=1>
<input type=hidden name=menuItem value=trivia>
<input type=hidden name=showTriviaResults value=$showTriviaResults>
<tr>
<td colspan=4>
<input type=submit name=Submit value=\"Skicka\" class=red_button>
</td>
</tr>
</table>
</form>
"

#------------------------------
# Showing Trivia Results Block
#------------------------------

if {$showTriviaResults} {
set thisQuestion {}; set thisCorrectAnswerID 0; set thisTriviaID 0
for {set i [lsearch $triviaAttrs {expDate}]} {$i < [llength
$triviaAttrs]} {incr i $triviaAttrCount} {

if {[expr {[lindex $triviaAttrs [expr {$i + 1}]] > $midnightNow}]} {
# YOU ARE AT THE FIRST ROW OF THE FIRST XML GROUP WITH AN UNEXPIRED
DATE
set k 1; set hasFoundTheseAnswers 0
for {set j $i} {$j > 0} {incr j -2} {
# WORK YOUR WAY BACKWARDS FROM THAT ROW TO GET THE ELEMENTS YOU
NEED EXCEPT FOR ANSWER FOR NOW
switch [lindex $triviaAttrs $j] {
question {set thisQuestion [lindex $triviaAttrs [expr {$j + 1}]]}
correctAnswerID {set thisCorrectAnswerID [lindex $triviaAttrs
[expr {$j + 1}]]}
triviaID {set thisTriviaID [lindex $triviaAttrs [expr {$j + 1}]]}

id {break}
default {# DO NOTHING}
}
}
set myCurrentTriviaID [lindex $triviaAttrs [expr {[lsearch -exact
$triviaAttrs {triviaID}] + $j + 1}]]
for {set m $j} {$m < [llength $triviaAttrs]} {incr m
$triviaAttrCount} {
# NOW YOU GRAB YOUR ANSWERS THROUGHOUT THE ENTIRE XML ROW GROUP
if {[lindex $triviaAttrs [expr {[lsearch -exact $triviaAttrs
{triviaID}] + $m + 1}]] == $myCurrentTriviaID} {
set answerArray($k) [lindex $triviaAttrs [expr {[lsearch -exact
$triviaAttrs {answer}] + $m + 1}]]
incr k
} else {
break
}
}
break; # YOU FOUND EVERYTHING IN THE FIRST CURRENT XML ROW GROUP -
NOW YOU CAN COMPARE TO RESULTS XML
}

}
for {set i [lsearch $trivResultsAttrs {triviaID}]} {$i < [llength
$trivResultsAttrs]} {incr i $trivResultsAttrCount} {
if {[expr {[lindex $trivResultsAttrs [expr {$i + 1}]] >
$thisTriviaID}] || $thisTriviaID == 0} {
# GONE BEYOND THE XML ROW GROUPING FOR CURRENT TRIVIA OR AT END OF
LIST
break
} elseif {[expr {[lindex $trivResultsAttrs [expr {$i + 1}]] ==
$thisTriviaID}]} {
# FOUND RESPONDER'S GROUP LISTING TO CURRENT TRIVIA
for {set j [expr {$i - 2}]} {$j < [expr {$i - 2 +
$trivResultsAttrCount}]} {incr j 2} {
set this_[lindex $trivResultsAttrs $j] "[lindex $trivResultsAttrs
[expr {$j + 1}]]"
}
append blah "
Name: <font color=990000>$this_firstname
$this_lastname</font><br>
Question: <font color=666600>$thisQuestion</font><br>
Their Answer: <font
color=6996699><b>$answerArray($this_answerID)</b></font><br>
"
if {$this_answerID == $thisCorrectAnswerID} {
append blah {
<font color=006699>CORRECT</font>
}
}
append blah {
<br><div align=left><hr width=200 color=000099
bgcolor=000099></div>
}
}
}
}

#---END OF SHOW TRIVIA RESULTS HTML DISPLAY
BLOCK-------------------------------------------------------------------

append blah "
<p>
<a
href=/cma/index.php?hasPassedCookie=1&menuItem=trivia&showTriviaResults=[if
{$showTriviaResults} {set x 0} else {set x 1}]>[

if {$showTriviaResults} {set x {Hide}} else {set x {Show}}

] Trivia Results</a>
"







Sorry this is all I can provide for now. Will provide more when I
return from vacation.

Phil

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com