X-Git-Url: https://defaria.com/gitweb/?a=blobdiff_plain;f=maps%2Flib%2FMAPSUtil.pm;h=b0865d702d11530e8927521798ed6afd69171401;hb=7ad5fd1a2d54b940018de904485ce560562af176;hp=4a2a97da79f77763f2098cf25614289b27dc3acc;hpb=16babf81ce331af378de565ba73e927ff5491f65;p=clearscm.git diff --git a/maps/lib/MAPSUtil.pm b/maps/lib/MAPSUtil.pm index 4a2a97d..b0865d7 100644 --- a/maps/lib/MAPSUtil.pm +++ b/maps/lib/MAPSUtil.pm @@ -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;