[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GT] SVN Commit r602 - trunk/Scripts
Author: thomas
Date: 2008-04-14 04:23:47 +0200 (Mon, 14 Apr 2008)
New Revision: 602
Modified:
trunk/Scripts/scan.pl
Log:
Move ras date check into a subroutine.
Modified: trunk/Scripts/scan.pl
===================================================================
--- trunk/Scripts/scan.pl 2008-04-14 02:04:17 UTC (rev 601)
+++ trunk/Scripts/scan.pl 2008-04-14 02:23:47 UTC (rev 602)
@@ -224,137 +224,11 @@
# get date string from command line
my $date = shift;
+# date check introduced by ras
+# comment out if not desired
+($date, $start, $end) = check_date($timeframe, $date, $start, $end);
-##############################################################################
-#
-# if you don't like this date checking, thing you have found a bug and want
-# to test with and without it set skip_date_checks below to 1 all added code
-# will be bypassed
-#
-my $skip_date_checks = 0; # set to 1 to skip all ras hack date checking
-goto SKIP_DATE_CHECKS if ( $skip_date_checks );
-#
-#
-##############################################################################
-
-# assumptions: date is the day of interest
-# start and end dates define time span under analysis
-# date is expected to be within that time span
-# timeframe is the time period chunk size
-# start and end dates must match the selected timeframe
-#
-#
-# datetime formats permitted
-# yyyy-mm-dd with or without leading zeros
-# yyyymmdd with required leading zeros
-# <date> hh:mm:ss with required separator and leading zeros
-if ( ! $date ) {
- print STDERR "$prog_name: error: require date parameter\n\n";
- print STDERR "date formats are YYYY-MM-DD with or without leading zeros\n";
- print STDERR " YYYYMMDD leading zeros required\n\n";
- print STDERR "time formats for sub day timeframes is:\n";
- print STDERR " <date> HH:MM:SS\n\n";
- print STDERR "explicit timeframe required if time included in date\n\n";
- usage();
- exit 1;
-}
-
-my $tf;
-my $time;
-my $err_msg;
-
-my $in_date = $date;
-my $in_start = $start if ( $start );
-my $in_end = $end if ( $end );
-
-if ( $timeframe ) {
- $tf = GT::DateTime::name_to_timeframe($timeframe);
-} else {
- # assume default is $DAY timeframe
- $tf = $DAY;
-}
-
-my ( $d_yr, $d_mn, $d_dy, $d_tm );
-if ( ! parse_date_str( \$date, \$err_msg ) ) {
- die "$prog_name: error: $err_msg\n";
-} else {
- ( $d_yr, $d_mn, $d_dy, $d_tm ) = split /[- ]/, $date;
- }
-
-my ( $s_yr, $s_mn, $s_dy, $s_tm );
-if ( $start ) {
- if ( ! parse_date_str( \$start, \$err_msg ) ) {
- die "$prog_name: error: \$err_msg\n";
- } else {
- ( $s_yr, $s_mn, $s_dy, $s_tm ) = split /[- ]/, $start;
- }
-}
-
-my ( $e_yr, $e_mn, $e_dy, $e_tm );
-if ( $end ) {
- if ( ! parse_date_str( \$end, \$err_msg ) ) {
- die "$prog_name: error: \$err_msg\n";
- } else {
- ( $e_yr, $e_mn, $e_dy, $e_tm ) = split /[- ]/, $end;
- }
-}
-
-if ( $start && $end ) {
- # $start must be prior to $end
- if (Date_to_Days($s_yr, $s_mn, $s_dy) >=
- Date_to_Days($e_yr, $e_mn, $e_dy)) {
- warn "$prog_name: --start date must be prior to --end date ($start before $end)\n";
- }
-}
-
-if ( $date && $end ) {
- # $date must be $end or before
- if (Date_to_Days($d_yr, $d_mn, $d_dy) >
- Date_to_Days($e_yr, $e_mn, $e_dy)) {
- warn "$prog_name: date must be prior to or equal --end date ($date before $end)\n";
- }
-}
-
-if ( $date && $start ) {
- # $start must be prior to $date
- if (Date_to_Days($s_yr, $s_mn, $s_dy) >=
- Date_to_Days($d_yr, $d_mn, $d_dy)) {
- warn "$prog_name: --start must be prior to date ($start before $date)\n";
- }
-}
-
-# this is really debug code
-if ( $verbose ) {
- print STDERR "\npre timeframe adjust:\n";
- print STDERR "date:\t$date\n";
- print STDERR "start:\t$start\n";
- print STDERR "end:\t$end\n";
-}
-
-# timeframe relative date conversions
-if ( $start && $tf != $DAY ) {
- $start = GT::DateTime::convert_date($start, $DAY, $tf);
-}
-
-if ( $end && $tf != $DAY ) {
- $end = GT::DateTime::convert_date($end, $DAY, $tf);
-}
-
-if ( $tf != $DAY && $tf > $DAY ) {
- $date = GT::DateTime::convert_date($date, $DAY, $tf);
-}
-
-# this is really debug code
-if ( $verbose ) {
- print STDERR "\npost timeframe adjust:\n";
- print STDERR "date:\t$date\n";
- print STDERR "start:\t$start\n";
- print STDERR "end:\t$end\n\n";
-}
-
-SKIP_DATE_CHECKS:
-
# Build the list of systems to test
# <> is last command line parameter -- filename of systems or signals
# reads the entire file into the desc_systems array
@@ -580,7 +454,129 @@
}
}
+sub check_date {
+ my ($timeframe, $date, $start, $end) = @_;
+ # assumptions: date is the day of interest
+ # start and end dates define time span under analysis
+ # date is expected to be within that time span
+ # timeframe is the time period chunk size
+ # start and end dates must match the selected timeframe
+ #
+ #
+ # datetime formats permitted
+ # yyyy-mm-dd with or without leading zeros
+ # yyyymmdd with required leading zeros
+ # <date> hh:mm:ss with required separator and leading zeros
+ if ( ! $date ) {
+ print STDERR "$prog_name: error: require date parameter\n\n";
+ print STDERR "date formats are YYYY-MM-DD with or without leading zeros\n";
+ print STDERR " YYYYMMDD leading zeros required\n\n";
+ print STDERR "time formats for sub day timeframes is:\n";
+ print STDERR " <date> HH:MM:SS\n\n";
+ print STDERR "explicit timeframe required if time included in date\n\n";
+ usage();
+ exit 1;
+ }
+
+ my $tf;
+ my $time;
+ my $err_msg;
+
+ my $in_date = $date;
+ my $in_start = $start if ( $start );
+ my $in_end = $end if ( $end );
+
+ if ( $timeframe ) {
+ $tf = GT::DateTime::name_to_timeframe($timeframe);
+ } else {
+ # assume default is $DAY timeframe
+ $tf = $DAY;
+ }
+
+ my ( $d_yr, $d_mn, $d_dy, $d_tm );
+ if ( ! parse_date_str( \$date, \$err_msg ) ) {
+ die "$prog_name: error: $err_msg\n";
+ } else {
+ ( $d_yr, $d_mn, $d_dy, $d_tm ) = split /[- ]/, $date;
+ }
+
+ my ( $s_yr, $s_mn, $s_dy, $s_tm );
+ if ( $start ) {
+ if ( ! parse_date_str( \$start, \$err_msg ) ) {
+ die "$prog_name: error: \$err_msg\n";
+ } else {
+ ( $s_yr, $s_mn, $s_dy, $s_tm ) = split /[- ]/, $start;
+ }
+ }
+
+ my ( $e_yr, $e_mn, $e_dy, $e_tm );
+ if ( $end ) {
+ if ( ! parse_date_str( \$end, \$err_msg ) ) {
+ die "$prog_name: error: \$err_msg\n";
+ } else {
+ ( $e_yr, $e_mn, $e_dy, $e_tm ) = split /[- ]/, $end;
+ }
+ }
+
+ if ( $start && $end ) {
+ # $start must be prior to $end
+ if (Date_to_Days($s_yr, $s_mn, $s_dy) >=
+ Date_to_Days($e_yr, $e_mn, $e_dy)) {
+ warn "$prog_name: --start date must be prior to --end date ($start before $end)\n";
+ }
+ }
+
+ if ( $date && $end ) {
+ # $date must be $end or before
+ if (Date_to_Days($d_yr, $d_mn, $d_dy) >
+ Date_to_Days($e_yr, $e_mn, $e_dy)) {
+ warn "$prog_name: date must be prior to or equal --end date ($date before $end)\n";
+ }
+ }
+
+ if ( $date && $start ) {
+ # $start must be prior to $date
+ if (Date_to_Days($s_yr, $s_mn, $s_dy) >=
+ Date_to_Days($d_yr, $d_mn, $d_dy)) {
+ warn "$prog_name: --start must be prior to date ($start before $date)\n";
+ }
+ }
+
+ # this is really debug code
+ if ( $verbose ) {
+ print STDERR "\npre timeframe adjust:\n";
+ print STDERR "date:\t$date\n";
+ print STDERR "start:\t$start\n";
+ print STDERR "end:\t$end\n";
+ }
+
+ # timeframe relative date conversions
+ if ( $start && $tf != $DAY ) {
+ $start = GT::DateTime::convert_date($start, $DAY, $tf);
+ }
+
+ if ( $end && $tf != $DAY ) {
+ $end = GT::DateTime::convert_date($end, $DAY, $tf);
+ }
+
+ if ( $tf != $DAY && $tf > $DAY ) {
+ $date = GT::DateTime::convert_date($date, $DAY, $tf);
+ }
+
+ # this is really debug code
+ if ( $verbose ) {
+ print STDERR "\npost timeframe adjust:\n";
+ print STDERR "date:\t$date\n";
+ print STDERR "start:\t$start\n";
+ print STDERR "end:\t$end\n\n";
+ }
+
+ return ($date, $start, $end);
+
+}
+
+
sub usage {
print STDERR "$prog_name [ options ] symbols_file date spec_file [ spec_file ... ]\n";
print STDERR "\n";