Fixed long standing bug about displaying proper message
[clearscm.git] / maps / lib / MAPSUtil.pm
index 4a2a97d..b0865d7 100644 (file)
@@ -19,13 +19,16 @@ use warnings;
 
 use vars qw (@ISA @EXPORT);
 
-BEGIN {
-  $ENV{TZ}='America/Los_Angeles';
-} # BEGIN
+# Not sure why I was setting TZ to LA but I'm in Phoenix now. This is best
+# handled by configuring the OS correctly anyway.
+#BEGIN {
+#  $ENV{TZ}='America/Los_Angeles';
+#} # BEGIN
 
 @ISA = qw (Exporter);
 
-@EXPORT = qw (
+@EXPORT = qw(
+  CheckEmail
   FormatDate
   FormatTime
   SQLDatetime2UnixDatetime
@@ -36,7 +39,7 @@ BEGIN {
 
 sub Today2SQLDatetime;
 
-sub FormatDate {
+sub FormatDate($) {
   my ($date) = @_;
 
   return substr ($date, 5, 2)  . '/' .
@@ -44,7 +47,7 @@ sub FormatDate {
          substr ($date, 0, 4);
 } # FormatDate
 
-sub FormatTime {
+sub FormatTime($) {
   my ($time) = @_;
 
   my $hours   = substr $time, 0, 2;
@@ -60,7 +63,7 @@ sub FormatTime {
   return "$hours:$minutes:$seconds $AmPm";
 } # FormatTime
 
-sub SQLDatetime2UnixDatetime {
+sub SQLDatetime2UnixDatetime($) {
   my ($sqldatetime) = @_;
 
   my %months = (
@@ -86,7 +89,7 @@ sub SQLDatetime2UnixDatetime {
   return $months {$month} . " $day, $year \@ $time";
 } # SQLDatetime2UnixDatetime
 
-sub SubtractDays {
+sub SubtractDays($$) {
   my ($timestamp,$nbr_of_days) = @_;
 
   my @months = (
@@ -122,15 +125,12 @@ sub SubtractDays {
   $days += $day - $nbr_of_days;
 
   # Compute $days_in_year
-  my $days_in_year;
+  my $days_in_year = (($year % 4) == 0) ? 366 : 365;
 
   # Adjust if crossing year boundary
   if ($days <= 0) {
     $year--;
-    $days_in_year = (($year % 4) == 0) ? 366 : 365;
     $days = $days_in_year + $days;
-  } else {
-    $days_in_year = (($year % 4) == 0) ? 366 : 365;
   } # if
 
   # Convert back
@@ -145,7 +145,7 @@ sub SubtractDays {
   } # while
 
   # Prefix month with 0 if necessary
-  $month++;
+  $month++ unless $month == 12;
   if ($month < 10) {
     $month = '0' . $month;
   } # if
@@ -259,8 +259,27 @@ sub UnixDatetime2SQLDatetime($) {
   return "$year-$month-$day $time";
 } # UnixDatetime2SQLDatetime
 
-sub Today2SQLDatetime {
+sub Today2SQLDatetime() {
   return UnixDatetime2SQLDatetime(scalar localtime);
 } # Today2SQLDatetime
 
+sub CheckEmail($$) {
+  my ($username, $domain) = @_;
+
+  # Check to see if a full email address in either $username or $domain
+  if ($username eq '') {
+    return '' if $domain eq '';
+
+    if ($domain =~ /(.*)\@(.*)/) {
+      ($username, $domain) = split '@', $domain;
+    } # if
+  } elsif ($domain eq '') {
+    if ($username =~ /(.*)\@(.*)/) {
+      ($username, $domain) = split '@', $username;
+    } # if
+  } # if
+
+   return lc "$username\@$domain";
+} # CheckEmail
+
 1;