Commit d599467b authored by Gary Wong's avatar Gary Wong

Force the Reservation module to accept/supply Unix timestamps on reservations.

Then convert to and from the local time on input and output in "reserve".
parent cad85450
......@@ -136,7 +136,10 @@ sub Lookup($$;$$$$)
my $pid_idx = $project->pid_idx();
$query_result = DBQueryWarn( "SELECT * FROM future_reservations " .
$query_result = DBQueryWarn( "SELECT *, UNIX_TIMESTAMP(start) AS s, " .
"UNIX_TIMESTAMP(end) AS e, " .
"UNIX_TIMESTAMP(created) AS c " .
"FROM future_reservations " .
"WHERE pid_idx='$pid_idx' AND " .
"nodes='$nodes' AND " .
"type='$type' AND " .
......@@ -149,7 +152,10 @@ sub Lookup($$;$$$$)
# Look up by ID.
my $idx = $_[ 1 ];
$query_result = DBQueryWarn( "SELECT * FROM future_reservations " .
$query_result = DBQueryWarn( "SELECT *, UNIX_TIMESTAMP(start) AS s, " .
"UNIX_TIMESTAMP(end) AS e, " .
"UNIX_TIMESTAMP(created) AS c " .
"FROM future_reservations " .
"WHERE idx='$idx'" );
return undef
......@@ -163,8 +169,9 @@ sub Lookup($$;$$$$)
$self->{'PID'} = $record->{'pid'};
$self->{'PID_IDX'} = $record->{'pid_idx'};
$self->{'EID'} = undef;
$self->{'START'} = $record->{'start'};
$self->{'END'} = $record->{'end'};
$self->{'START'} = $record->{'s'};
$self->{'END'} = $record->{'e'};
$self->{'CREATED'} = $record->{'c'};
$self->{'TYPE'} = $record->{'type'};
$self->{'NODES'} = $record->{'nodes'};
$self->{'UID'} = $record->{'uid'};
......@@ -183,6 +190,7 @@ sub pid_idx($) { return $_[0]->{"PID_IDX"}; }
sub eid($) { return $_[0]->{"EID"}; }
sub start($) { return $_[0]->{"START"}; }
sub end($) { return $_[0]->{"END"}; }
sub created($) { return $_[0]->{"CREATED"}; }
sub type($) { return $_[0]->{"TYPE"}; }
sub nodes($) { return $_[0]->{"NODES"}; }
sub uid($) { return $_[0]->{"UID"}; }
......@@ -304,6 +312,7 @@ sub Book($)
or return -1;
$self->{'IDX'} = $query_result->insertid();
$self->{'CREATED'} = time();
delete $cache{$type};
......
......@@ -25,6 +25,7 @@ use strict;
use English;
use Getopt::Std;
use Date::Parse;
use POSIX;
#
# Configure variables
......@@ -97,6 +98,12 @@ sub readfile($) {
return $contents;
}
sub convert($) {
my ($unixtime) = @_;
return strftime( "%Y-%m-%d %H:%M", localtime( $unixtime ) );
}
#
# Turn off line buffering on output
#
......@@ -207,16 +214,18 @@ else {
# List all pending reservations.
#
if ($list) {
my $query = $type ? "SELECT idx, pid, nodes, type, start, end FROM " .
"future_reservations WHERE type='$type' ORDER BY start" :
"SELECT idx, pid, nodes, type, start, end FROM future_reservations " .
"ORDER BY start";
my $query = $type ? "SELECT idx, pid, nodes, type, " .
"UNIX_TIMESTAMP( start ) AS s, UNIX_TIMESTAMP( end ) AS e FROM " .
"future_reservations WHERE type='$type' ORDER BY s" :
"SELECT idx, pid, nodes, type, UNIX_TIMESTAMP( start ) AS s, " .
"UNIX_TIMESTAMP( end ) AS e FROM future_reservations " .
"ORDER BY s";
my $query_result = DBQueryFatal( $query );
if( $query_result->numrows ) {
print "Index Start End Project Nodes Type\n";
print "----- ----- --- ------- ----- ----\n";
print "Index Start End Project Nodes Type\n";
print "----- ----- --- ------- ----- ----\n";
}
while( my $row = $query_result->fetchrow_hashref() ) {
......@@ -224,10 +233,10 @@ if ($list) {
my $pid = $row->{'pid'};
my $nodes = $row->{'nodes'};
my $type = $row->{'type'};
my $start = $row->{'start'};
my $end = $row->{'end'};
my $start = convert( $row->{'s'} );
my $end = convert( $row->{'e'} );
printf( "%5d %19s %19s %-19s %5d %s\n", $idx, $start, $end, $pid, $nodes, $type );
printf( "%5d %16s %16s %-19s %5d %s\n", $idx, $start, $end, $pid, $nodes, $type );
}
exit(0);
......@@ -260,26 +269,28 @@ if( !defined( $clear_idx ) ) {
# Show and exit.
#
if ($info) {
my $query = $type ? "SELECT uid, nodes, type, start, end FROM " .
my $query = $type ? "SELECT uid, nodes, type, " .
"UNIX_TIMESTAMP( start ) AS s, UNIX_TIMESTAMP( end ) AS e FROM " .
"future_reservations WHERE type='$type' AND pid_idx=$pid_idx " .
"ORDER BY start" : "SELECT uid, nodes, type, start, end FROM " .
"future_reservations WHERE pid_idx=$pid_idx ORDER BY start";
"ORDER BY s" : "SELECT uid, nodes, type, " .
"UNIX_TIMESTAMP( start ) AS s, UNIX_TIMESTAMP( end ) AS e FROM " .
"future_reservations WHERE pid_idx=$pid_idx ORDER BY s";
my $query_result = DBQueryFatal( $query );
if( $query_result->numrows ) {
print "Start End User Nodes Type\n";
print "----- --- ---- ----- ----\n";
print "Start End User Nodes Type\n";
print "----- --- ---- ----- ----\n";
}
while( my $row = $query_result->fetchrow_hashref() ) {
my $uid = $row->{'uid'};
my $nodes = $row->{'nodes'};
my $type = $row->{'type'};
my $start = $row->{'start'};
my $end = $row->{'end'};
my $start = convert( $row->{'s'} );
my $end = convert( $row->{'e'} );
printf( "%19s %19s %-19s %5d %s\n", $start, $end, $uid, $nodes, $type );
printf( "%16s %16s %-19s %5d %s\n", $start, $end, $uid, $nodes, $type );
}
exit(0);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment