From owner-svn-src-user@FreeBSD.ORG Thu Apr 17 11:56:39 2014 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 415CFD01; Thu, 17 Apr 2014 11:56:39 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 2E056119C; Thu, 17 Apr 2014 11:56:39 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.8/8.14.8) with ESMTP id s3HBudZZ014897; Thu, 17 Apr 2014 11:56:39 GMT (envelope-from des@svn.freebsd.org) Received: (from des@localhost) by svn.freebsd.org (8.14.8/8.14.8/Submit) id s3HBud1X014896; Thu, 17 Apr 2014 11:56:39 GMT (envelope-from des@svn.freebsd.org) Message-Id: <201404171156.s3HBud1X014896@svn.freebsd.org> From: Dag-Erling Smørgrav Date: Thu, 17 Apr 2014 11:56:39 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: svn commit: r264594 - user/des/fbp/lib/FBP/Schema/Result X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.17 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 17 Apr 2014 11:56:39 -0000 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