Date: Thu, 17 Apr 2014 11:56:39 +0000 (UTC) From: Dag-Erling Smørgrav <des@FreeBSD.org> To: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: svn commit: r264594 - user/des/fbp/lib/FBP/Schema/Result Message-ID: <201404171156.s3HBud1X014896@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201404171156.s3HBud1X014896>