26
26
use warnings FATAL => 'all';
27
27
use English qw(-no_match_vars);
28
use constant MKDEBUG => $ENV{MKDEBUG} || 0;
28
use constant PTDEBUG => $ENV{PTDEBUG} || 0;
30
30
use Time::Local qw(timegm timelocal);
31
31
use Digest::MD5 qw(md5_hex);
230
230
: $suffix eq 'h' ? $n * 3600 # Hours
231
231
: $suffix eq 'd' ? $n * 86400 # Days
232
232
: $n; # default: Seconds
233
MKDEBUG && _d('ts is now - N[shmd]:', $n);
233
PTDEBUG && _d('ts is now - N[shmd]:', $n);
234
234
return time - $n;
236
236
elsif ( $val =~ m/^\d{9,}/ ) {
237
237
# unix timestamp 100000000 is roughly March, 1973, so older
238
238
# dates won't be caught here; they'll probably be mistaken
239
239
# for a MySQL slow log timestamp.
240
MKDEBUG && _d('ts is already a unix timestamp');
240
PTDEBUG && _d('ts is already a unix timestamp');
243
243
elsif ( my ($ymd, $hms) = $val =~ m/^(\d{6})(?:\s+(\d+:\d+:\d+))?/ ) {
244
MKDEBUG && _d('ts is MySQL slow log timestamp');
244
PTDEBUG && _d('ts is MySQL slow log timestamp');
245
245
$val .= ' 00:00:00' unless $hms;
246
246
return unix_timestamp(parse_timestamp($val));
248
248
elsif ( ($ymd, $hms) = $val =~ m/^(\d{4}-\d\d-\d\d)(?:[T ](\d+:\d+:\d+))?/) {
249
MKDEBUG && _d('ts is properly formatted timestamp');
249
PTDEBUG && _d('ts is properly formatted timestamp');
250
250
$val .= ' 00:00:00' unless $hms;
251
251
return unix_timestamp($val);
254
MKDEBUG && _d('ts is MySQL expression');
254
PTDEBUG && _d('ts is MySQL expression');
255
255
return $callback->($val) if $callback && ref $callback eq 'CODE';
258
MKDEBUG && _d('Unknown ts type:', $val);
258
PTDEBUG && _d('Unknown ts type:', $val);
263
263
sub make_checksum {
264
264
my ( $val ) = @_;
265
265
my $checksum = uc substr(md5_hex($val), -16);
266
MKDEBUG && _d($checksum, 'checksum for', $val);
266
PTDEBUG && _d($checksum, 'checksum for', $val);
267
267
return $checksum;