svn commit: r264594 - user/des/fbp/lib/FBP/Schema/Result

Dag-Erling Smørgrav des at FreeBSD.org
Thu Apr 17 11:56:39 UTC 2014


Author: des
Date: Thu Apr 17 11:56:38 2014
New Revision: 264594
URL: http://svnweb.freebsd.org/changeset/base/264594

Log:
  Add started and ended predicates and reimplement the active predicate
  as (started && !ended).

Modified:
  user/des/fbp/lib/FBP/Schema/Result/Poll.pm

Modified: user/des/fbp/lib/FBP/Schema/Result/Poll.pm
==============================================================================
--- user/des/fbp/lib/FBP/Schema/Result/Poll.pm	Thu Apr 17 11:52:27 2014	(r264593)
+++ user/des/fbp/lib/FBP/Schema/Result/Poll.pm	Thu Apr 17 11:56:38 2014	(r264594)
@@ -166,6 +166,34 @@ __PACKAGE__->has_many(
 
 use DateTime;
 
+=index2 started
+
+True if the poll had, has or will have started at the specified date
+and time.
+
+=cut
+
+sub started($;$) {
+    my ($self, $when) = @_;
+
+    $when //= DateTime->now();
+    return DateTime->compare($when, $self->starts) >= 0;
+}
+
+=index2 ended
+
+True if the poll had, has or will have ended at the specified date and
+time.
+
+=cut
+
+sub ended($;$) {
+    my ($self, $when) = @_;
+
+    $when //= DateTime->now();
+    return DateTime->compare($when, $self->ends) <= 0;
+}
+
 =index2 active
 
 True if the poll was, is or will be active at the specified date and
@@ -177,8 +205,7 @@ sub active($;$) {
     my ($self, $when) = @_;
 
     $when //= DateTime->now();
-    return DateTime->compare($when, $self->starts) >= 0 &&
-	DateTime->compare($when, $self->ends) <= 0;
+    return $self->started($when) && !$self->ended($when);
 }
 
 =head2 votes


More information about the svn-src-user mailing list