Changeset 29750 for trunk/tools/czartool/MySQLDb.pm
- Timestamp:
- Nov 10, 2010, 3:36:30 PM (15 years ago)
- File:
-
- 1 edited
-
trunk/tools/czartool/MySQLDb.pm (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/czartool/MySQLDb.pm
r29741 r29750 131 131 ########################################################################### 132 132 # 133 # Formats a date/time string in a way suitable for TIMEDIFF calls 134 # 135 ########################################################################### 136 sub formatTimeForDiff { 137 my ($self, $time) = @_; 138 139 if (${$time} =~ m/^[0-9]{4}-[0-9]{2}-[0-9]{2}.*/) {${$time} = $self->getFullDate(${$time});} 140 elsif(${$time} !~ m/^[0-9]+:[0-9]{2}:[0-9]{2}$/) {return 0;} 141 142 return 1; 143 } 144 145 ########################################################################### 146 # 133 147 # Finds the difference of two times 148 # 149 # Should be able to handle most date/time formats 134 150 # 135 151 ########################################################################### … … 139 155 if (!$time1 || !$time2) {return 0;} 140 156 157 if (!$self->formatTimeForDiff(\$time1) || !$self->formatTimeForDiff(\$time2)) {return 0;} 158 141 159 my $query = $self->{_db}->prepare(<<SQL); 142 160 SELECT TIMEDIFF('$time1','$time2'); … … 174 192 175 193 if (!$time1 || !$time2) {return 0;} 194 if (!$self->formatTimeForDiff(\$time1) || !$self->formatTimeForDiff(\$time2)) {return 0;} 176 195 177 196 my $query = $self->{_db}->prepare(<<SQL); … … 207 226 my ($self, $time1, $time2) = @_; 208 227 209 my $query = $self->{_db}->prepare(<<SQL); 210 SELECT TIME_TO_SEC(TIMEDIFF('$time1', '$time2')); 211 SQL 212 $query->execute; 213 214 return (scalar $query->fetchrow_array() > 0) ? 0 : 1; 228 if (!$time1 || !$time2) {return 0;} 229 if (!$self->formatTimeForDiff(\$time1) || !$self->formatTimeForDiff(\$time2)) {return 0;} 230 231 my $query = $self->{_db}->prepare(<<SQL); 232 SELECT TIME_TO_SEC(TIMEDIFF('$time1', '$time2')); 233 SQL 234 $query->execute; 235 236 return (scalar $query->fetchrow_array() >= 0) ? 0 : 1; 215 237 } 216 238
Note:
See TracChangeset
for help on using the changeset viewer.
