From ruby-talk-admin@ruby-lang.org Thu Dec 15 23:41:37 2005 Received: from kankan.nagaokaut.ac.jp (kankan.nagaokaut.ac.jp [133.44.2.24]) by blade.nagaokaut.ac.jp (8.12.3/8.12.3/Debian-6.6) with ESMTP id jBFEfbZk021385; Thu, 15 Dec 2005 23:41:37 +0900 Received: from funfun.nagaokaut.ac.jp (funfun.nagaokaut.ac.jp [133.44.2.201]) by kankan.nagaokaut.ac.jp (Postfix) with ESMTP id 624E15A15; Thu, 15 Dec 2005 23:41:38 +0900 (JST) Received: from localhost (localhost.nagaokaut.ac.jp [127.0.0.1]) by funfun.nagaokaut.ac.jp (Postfix) with ESMTP id 10114F0484A; Thu, 15 Dec 2005 23:41:42 +0900 (JST) Received: from voscc.nagaokaut.ac.jp (voscc.nagaokaut.ac.jp [133.44.1.100]) by funfun.nagaokaut.ac.jp (Postfix) with ESMTP id CC6E0F04847; Thu, 15 Dec 2005 23:41:40 +0900 (JST) Received: from beryllium.ruby-lang.org (beryllium.ruby-lang.org [210.163.138.100]) by voscc.nagaokaut.ac.jp (Postfix) with ESMTP id 64A01630029; Thu, 15 Dec 2005 23:41:43 +0900 (JST) Received: from beryllium.ruby-lang.org (beryllium.ruby-lang.org [127.0.0.1]) by beryllium.ruby-lang.org (Postfix) with ESMTP id A274033C33; Thu, 15 Dec 2005 23:41:39 +0900 (JST) Received: from localhost (beryllium.ruby-lang.org [127.0.0.1]) by beryllium.ruby-lang.org (Postfix) with ESMTP id A912033EF4 for ; Thu, 15 Dec 2005 23:41:31 +0900 (JST) Received: from beryllium.ruby-lang.org ([127.0.0.1]) by localhost (beryllium.ruby-lang.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 01608-09 for ; Thu, 15 Dec 2005 23:41:31 +0900 (JST) Received: from vwall2.nyc.gov (vwall2.nyc.gov [161.185.1.12]) by beryllium.ruby-lang.org (Postfix) with ESMTP id 0F11A33A93 for ; Thu, 15 Dec 2005 23:41:30 +0900 (JST) Received: from vwall2.nyc.gov (localhost [127.0.0.1]) by vwall2.nyc.gov (8.12.10/8.12.10) with ESMTP id jBFEfPFH022257 for ; Thu, 15 Dec 2005 09:41:25 -0500 (EST) Received: from citymail2.nycnet (citymail2 [10.152.8.72]) by vwall2.nyc.gov (8.12.10/8.12.10) with ESMTP id jBFEfOkh022228 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Thu, 15 Dec 2005 09:41:25 -0500 (EST) Received: from citymail2.nycnet (localhost [127.0.0.1]) by citymail2.nycnet (8.13.0/8.13.0) with ESMTP id jBFEfO42024247 for ; Thu, 15 Dec 2005 09:41:24 -0500 (EST) Received: from mtsvr009.doitt.nycnet (mtsvr009.doitt.nycnet [10.152.32.35]) by citymail2.nycnet (8.13.0/8.13.0) with ESMTP id jBFEfNDH024242 for ; Thu, 15 Dec 2005 09:41:23 -0500 (EST) Received: from doittmail01.doitt.nycnet ([10.152.32.32]) by mtsvr009.doitt.nycnet with Microsoft SMTPSVC(6.0.3790.1830); Thu, 15 Dec 2005 09:41:23 -0500 Delivered-To: ruby-talk@ruby-lang.org Date: Thu, 15 Dec 2005 23:41:32 +0900 Posted: Thu, 15 Dec 2005 09:41:22 -0500 From: "Lipper, Matthew" Reply-To: ruby-talk@ruby-lang.org Subject: Re: Runt: Matching the year To: ruby-talk@ruby-lang.org (ruby-talk ML) Message-Id: <37FEA507FBF9D34BA56FBA5970F143A609135170@DOITTMAIL01.doitt.nycnet> X-ML-Name: ruby-talk X-Mail-Count: 34 X-MLServer: fml [fml 4.0.3 release (20011202/4.0.3)]; post only (only members can post) X-ML-Info: If you have a question, send e-mail with the body "help" (without quotes) to the address ruby-talk-ctl@ruby-lang.org; help= X-Original-To: ruby-talk@ruby-lang.org X-MimeOLE: Produced By Microsoft Exchange V6.5.7226.0 Content-class: urn:content-classes:message X-MS-Has-Attach: X-MS-TNEF-Correlator: Thread-Topic: Runt: Matching the year Thread-Index: AcYBfhrkoOlShCebQoOlKxNxm8e6DQAAHIaA X-OriginalArrivalTime: 15 Dec 2005 14:41:23.0472 (UTC) FILETIME=[9EE4F100:01C60185] X-Virus-Scanned: by amavisd-new-20030616-p10 (Debian) at ruby-lang.org X-Spam-Checker-Version: SpamAssassin 3.0.3 (2005-04-27) on beryllium.ruby-lang.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=7.0 tests=AWL,BAYES_00, CONTENT_TYPE_PRESENT,FAKEDWORD_ATMARK,FAKEDWORD_ONE, FAKEDWORD_VERTICALLINE,MIMEQENC,QENCPTR1,RCVDFRMLOCALIP,THREAD_INDEX, THREAD_TOPIC autolearn=no version=3.0.3 Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Precedence: bulk Lines: 70 List-Id: ruby-talk.ruby-lang.org List-Software: fml [fml 4.0.3 release (20011202/4.0.3)] List-Post: List-Owner: List-Help: List-Unsubscribe: X-Virus-Scanned: by AMaViS snapshot-20020531 Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from quoted-printable to 8bit by blade.nagaokaut.ac.jp id jBFEfbZk021385 > > I downloaded runt to do some temporal expression work, and > was wondering if there's any way to match against a year. > From what I can tell I can match against month, day, hour, > min, sec, but not the year. Well, strictly speaking you could use a DateRange constructed with January 1st and December 31st of the year(s) in question but this is a pain... > Basically I'd like to have a timex that matches all dates > with the year 2005. If I create a date that has the year > 2006, then include? > should return false for that particular date. Am I missing > something in the docs? I'd appreciate any help. > > Pat > > I've just added the following class to CVS (apologize if Outlook mangles the layout) # Simple expression which returns true if the supplied arguments # occur within the given year. # class YearTE def initialize(year) @year = year end def include?(date) return date.year == @year end end For an example of usage see the test case in test/temporalexpressiontest.rb. Here's an excerpt: def test_year_te # second sun of any month second_sun = DIMonth.new(Second, Sunday) # simple year matching expression which will return true for # any date in 2005 year_te = YearTE.new(2005) # Second Sunday of a month in 2002 dt_in_2002 = Date.civil(2002,9,8) # Second Sunday of a month in 2005 dt_in_2005 = Date.civil(2005,12,11) # Matches assert(year_te.include?(dt_in_2005)) # Does not match assert(!year_te.include?(dt_in_2002)) end Feel free to contact me directly if you have any questions or problems. Thanks for using Runt! Matt