add ssl_no_verify option to all http exports, RT#29298
[freeside.git] / rt / lib / RT / Date.pm
index cc66e0f..9044d21 100644 (file)
@@ -2,7 +2,7 @@
 #
 # COPYRIGHT:
 #
-# This software is Copyright (c) 1996-2011 Best Practical Solutions, LLC
+# This software is Copyright (c) 1996-2013 Best Practical Solutions, LLC
 #                                          <sales@bestpractical.com>
 #
 # (Except where explicitly superseded by other copyright notices)
@@ -286,6 +286,8 @@ sub SetToStart {
     my %args = @_;
     my $tz = $args{'Timezone'} || '';
     my @localtime = $self->Localtime($tz);
+    #remove 'offset' so that DST is figured based on the resulting time.
+    pop @localtime;
 
     # This is the cleanest way to implement it, I swear.
     {
@@ -519,16 +521,21 @@ unix time.
 
 =cut
 
-sub AddMonth {
-    require Time::ParseDate;
+sub AddMonth {    
     my $self = shift;
-    my $date = ( 
-        Time::ParseDate::parsedate(
-            '1 month',
-            NOW => $self->Unix
-        )
-    );
-    return $self->Unix($date);
+    my %args = @_;
+    my @localtime = $self->Localtime($args{'Timezone'});
+    # remove offset, as with SetToStart
+    pop @localtime;
+    
+    $localtime[4]++; #month
+    if ( $localtime[4] == 12 ) {
+      $localtime[4] = 0;
+      $localtime[5]++; #year
+    }
+
+    my $new = $self->Timelocal($args{'Timezone'}, @localtime);
+    return $self->Unix($new);
 }
 
 =head2 Unix [unixtime]
@@ -597,6 +604,10 @@ sub Get
     my $self = shift;
     my %args = (Format => 'ISO', @_);
     my $formatter = $args{'Format'};
+    unless ( $self->ValidFormatter($formatter) ) {
+        RT->Logger->warning("Invalid date formatter '$formatter', falling back to ISO");
+        $formatter = 'ISO';
+    }
     $formatter = 'ISO' unless $self->can($formatter);
     return $self->$formatter( %args );
 }
@@ -635,6 +646,20 @@ sub Formatters
     return @FORMATTERS;
 }
 
+=head3 ValidFormatter FORMAT
+
+Returns a true value if C<FORMAT> is a known formatter.  Otherwise returns
+false.
+
+=cut
+
+sub ValidFormatter {
+    my $self   = shift;
+    my $format = shift;
+    return (grep { $_ eq $format } $self->Formatters and $self->can($format))
+                ? 1 : 0;
+}
+
 =head3 DefaultFormat
 
 =cut
@@ -697,8 +722,8 @@ sub LocalizedDateTime
     my %args = ( Date => 1,
                  Time => 1,
                  Timezone => '',
-                 DateFormat => 'date_format_full',
-                 TimeFormat => 'time_format_medium',
+                 DateFormat => '',
+                 TimeFormat => '',
                  AbbrDay => 1,
                  AbbrMonth => 1,
                  @_,
@@ -709,9 +734,12 @@ sub LocalizedDateTime
     return $self->loc("DateTime doesn't support format_cldr, you must upgrade to use this feature") 
         unless can DateTime::('format_cldr');
 
+    # Require valid names for the format methods
+    my $date_format = $args{DateFormat} =~ /^\w+$/
+                    ? $args{DateFormat} : 'date_format_full';
 
-    my $date_format = $args{'DateFormat'};
-    my $time_format = $args{'TimeFormat'};
+    my $time_format = $args{TimeFormat} =~ /^\w+$/
+                    ? $args{TimeFormat} : 'time_format_medium';
 
     my $lang = $self->CurrentUser->UserObj->Lang;
     unless ($lang) {
@@ -1092,9 +1120,6 @@ sub Timezone {
 }
 
 
-eval "require RT::Date_Vendor";
-die $@ if ($@ && $@ !~ qr{^Can't locate RT/Date_Vendor.pm});
-eval "require RT::Date_Local";
-die $@ if ($@ && $@ !~ qr{^Can't locate RT/Date_Local.pm});
+RT::Base->_ImportOverlays();
 
 1;