diff options
author | Christian Pointner <equinox@helsinki.at> | 2016-04-29 12:20:16 (GMT) |
---|---|---|
committer | Christian Pointner <equinox@helsinki.at> | 2016-04-29 12:26:46 (GMT) |
commit | ac81019e73049c079d3b9ea8c4187a04bc1833f4 (patch) | |
tree | 7fce5730e1660e77044fe0c2437062271cfc65aa /utils/rhrd-schedules | |
parent | fbe0303d3cc74f355beb49fcd6ac6d2cebe3851f (diff) |
improved show info output
moved command line parsing of week and dow to lib
Diffstat (limited to 'utils/rhrd-schedules')
-rwxr-xr-x | utils/rhrd-schedules | 59 |
1 files changed, 20 insertions, 39 deletions
diff --git a/utils/rhrd-schedules b/utils/rhrd-schedules index fa52226..2d509a9 100755 --- a/utils/rhrd-schedules +++ b/utils/rhrd-schedules @@ -144,45 +144,31 @@ sub show__day # (W1|W2|W3|W4|ALL) sub parse_rdweek { - my ($dow) = @_; - - if(uc($dow) eq "W1") { - return(1); - } elsif(uc($dow) eq "W2") { - return(2); - } elsif(uc($dow) eq "W3") { - return(3); - } elsif(uc($dow) eq "W4") { - return(4); - } elsif(uc($dow) eq "ALL") { - return(1, 2, 3, 4); + my ($week) = @_; + if(uc($week) eq "ALL") { + return (1, 2, 3, 4); } - return (); + my ($w, undef, $hint) = RHRD::utils::cmdline_rdweek($week); + unless(defined($w)) { + print "error parsing week: $week, " . $hint . " or ALL\n"; + return (); + } + return $w; } # (MO|TU|WE|TH|FR|SA|SU|ALL) sub parse_dow { my ($dow) = @_; - - if(uc($dow) eq "MO") { - return(1); - } elsif(uc($dow) eq "TU") { - return(2); - } elsif(uc($dow) eq "WE") { - return(3); - } elsif(uc($dow) eq "TH") { - return(4); - } elsif(uc($dow) eq "FR") { - return(5); - } elsif(uc($dow) eq "SA") { - return(6); - } elsif(uc($dow) eq "SU") { - return(7); - } elsif(uc($dow) eq "ALL") { - return(1, 2, 3, 4, 5, 6, 7); + if(uc($dow) eq "ALL") { + return (1, 2, 3, 4, 5, 6, 7); } - return (); + my ($d, undef, $hint) = RHRD::utils::cmdline_dow($dow); + unless(defined($d)) { + print "error parsing day of week: $dow, " . $hint . " or ALL\n"; + return (); + } + return $d; } sub cmp_dates @@ -204,15 +190,10 @@ sub gen_dates my ($week, $dow) = @_; my @weeks = parse_rdweek($week); - unless(@weeks) { - print "error parsing week: $week, must be one of W1, W2, W3, W4, ALL\n"; - return () - } + return () unless(@weeks); my @dows = parse_dow($dow); - unless(@dows) { - print "error parsing day of week: $dow, must be one of MO, TU, WE, TH, FR, SA, SU, ALL\n"; - return () - } + return () unless(@dows); + my $curweek = RHRD::utils::get_rd_week(); my @today = Date::Calc::Today(); |