perl-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Stas Bekman <s...@stason.org>
Subject [patch] ht_time interface
Date Tue, 29 Jan 2002 16:08:30 GMT
- interface to Apache::Time::ht_time
- compat wrapper Apache::Util::ht_time ( needs 
APR::Pool::from_current_request)
- tests for Apache::Time::ht_time and the wrapper Apache::Util

Index: xs/maps/apache_functions.map
===================================================================
RCS file: /home/cvs/modperl-2.0/xs/maps/apache_functions.map,v
retrieving revision 1.43
diff -u -r1.43 apache_functions.map
--- xs/maps/apache_functions.map	25 Jan 2002 04:04:22 -0000	1.43
+++ xs/maps/apache_functions.map	29 Jan 2002 15:55:58 -0000
@@ -255,8 +255,10 @@
  -ap_set_string_slot_lower
  -ap_set_deprecated

+MODULE=Apache::Time
+ ap_ht_time | | p, t=TIME_NOW, fmt=DEFAULT_TIME_FORMAT, gmt=TRUE
+
  MODULE=Apache::Util
- ap_ht_time
  !ap_rfc1413
   ap_escape_html
   #escape_uri
Index: lib/Apache/compat.pm
===================================================================
RCS file: /home/cvs/modperl-2.0/lib/Apache/compat.pm,v
retrieving revision 1.33
diff -u -r1.33 compat.pm
--- lib/Apache/compat.pm	29 Jan 2002 07:55:56 -0000	1.33
+++ lib/Apache/compat.pm	29 Jan 2002 15:55:57 -0000
@@ -25,6 +25,7 @@
  use Apache::Response ();
  use APR::Table ();
  use APR::Pool ();
+use Apache::Time ();
  use mod_perl ();
  use Symbol ();

@@ -377,6 +378,11 @@

      return $size;

+}
+
+# the new function now resides in Apache::Time and requires a pool object
+sub ht_time {
+    return Apache::Time::ht_time(APR::Pool::from_current_request(), @_);
  }

  1;
Index: t/response/TestApache/compat2.pm
===================================================================
RCS file: /home/cvs/modperl-2.0/t/response/TestApache/compat2.pm,v
retrieving revision 1.2
diff -u -r1.2 compat2.pm
--- t/response/TestApache/compat2.pm	29 Jan 2002 07:55:56 -0000	1.2
+++ t/response/TestApache/compat2.pm	29 Jan 2002 15:55:57 -0000
@@ -24,7 +24,7 @@
  sub handler {
      my $r = shift;

-    plan $r, tests => 34, todo => [23];
+    plan $r, tests => 35, todo => [23];

      $r->send_http_header('text/plain');

@@ -183,10 +183,22 @@

      # Apache::Util::size_string
      {
+        t_debug("Apache::Util::size_string");
          while (my($k, $v) = each %string_size) {
              ok t_cmp($v, Apache::Util::size_string($k));
          }
      }
+
+    # Apache::Util::ht_time
+    {
+        my $time_sec = time;
+        my $time_str = scalar localtime($time);
+        my $fmt = '%a %b %d %H:%M:%S %Y';
+        ok t_cmp($time_str,
+                 Apache::Util::ht_time($time_sec, $fmt, 0),
+                 "Apache::Util::ht_time");
+    }
+

      Apache::OK;
  }
--- /dev/null	Thu Jan  1 07:30:00 1970
+++ t/response/TestApache/time.pm	Tue Jan 29 18:40:47 2002
@@ -0,0 +1,46 @@
+package TestApache::time;
+
+use strict;
+use warnings FATAL => 'all';
+
+use Apache::Test;
+use Apache::TestUtil;
+use Apache::Const -compile => 'OK';
+
+use Apache::Time ();
+use APR::Pool ();
+use APR::Date ();
+
+my @formats = (
+    '%a, %d %b %Y %H:%M:%S %Z',
+    '%A, %d-%b-%y %H:%M:%S %Z',
+);
+
+sub handler {
+    my $r = shift;
+
+    plan $r, tests => 6;
+
+    # basic tests, hard to verify because of the timezone being the
+    # last arg, so without setting it to true we cannot verify data
+    t_debug("basic Apache::Time::ht_time tests")
+    ok Apache::Time::ht_time($r->pool);
+    ok Apache::Time::ht_time($r->pool, time);
+    ok Apache::Time::ht_time($r->pool, time, '%d %b %Y');
+    ok Apache::Time::ht_time($r->pool, time, '%d %b %Y', 0);
+
+    my $time_sec = time;
+    for my $fmt (@formats) {
+        my $time_str = Apache::Time::ht_time($r->pool, $time_sec, $fmt, 1);
+        ok t_cmp(APR::Date::parse_http($time_str),
+                 $time_sec,
+                 "Apache::Time::ht_time / $time_str"
+                );
+    }
+
+    Apache::OK;
+}
+
+1;
+__END__
+

_____________________________________________________________________
Stas Bekman             JAm_pH      --   Just Another mod_perl Hacker
http://stason.org/      mod_perl Guide   http://perl.apache.org/guide
mailto:stas@stason.org  http://ticketmaster.com http://apacheweek.com
http://singlesheaven.com http://perl.apache.org http://perlmonth.com/


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org


Mime
View raw message