comparison roundup/date.py @ 1509:1d4ebe2a88fc

hope this will make Range class a little bit clearer
author Andrey Lebedev <kedder@users.sourceforge.net>
date Mon, 10 Mar 2003 20:32:53 +0000
parents c101d2ff5a20
children 26f29449c494
comparison
equal deleted inserted replaced
1508:5c58ccad41ee 1509:1d4ebe2a88fc
13 # BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 13 # BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
14 # FOR A PARTICULAR PURPOSE. THE CODE PROVIDED HEREUNDER IS ON AN "AS IS" 14 # FOR A PARTICULAR PURPOSE. THE CODE PROVIDED HEREUNDER IS ON AN "AS IS"
15 # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE, 15 # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
16 # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. 16 # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
17 # 17 #
18 # $Id: date.py,v 1.47 2003-03-10 00:22:20 richard Exp $ 18 # $Id: date.py,v 1.48 2003-03-10 20:32:53 kedder Exp $
19 19
20 __doc__ = """ 20 __doc__ = """
21 Date, time and time interval handling. 21 Date, time and time interval handling.
22 """ 22 """
23 23
619 619
620 >>> Range("; 20:00 +1d") 620 >>> Range("; 20:00 +1d")
621 <Range from None to 2003-03-09.20:00:00> 621 <Range from None to 2003-03-09.20:00:00>
622 622
623 """ 623 """
624 def __init__(self, spec, type, **params): 624 def __init__(self, spec, Type, **params):
625 """Initializes Range of type <type> from given <spec> string. 625 """Initializes Range of type <Type> from given <spec> string.
626 626
627 Sets two properties - from_value and to_value. None assigned to any of 627 Sets two properties - from_value and to_value. None assigned to any of
628 this properties means "infinitum" (-infinitum to from_value and 628 this properties means "infinitum" (-infinitum to from_value and
629 +infinitum to to_value) 629 +infinitum to to_value)
630
631 The Type parameter here should be class itself (e.g. Date), not a
632 class instance.
633
630 """ 634 """
631 self.range_type = type 635 self.range_type = Type
632 re_range = r'(?:^|(?:from)?(.+?))(?:to(.+?)$|$)' 636 re_range = r'(?:^|(?:from)?(.+?))(?:to(.+?)$|$)'
633 re_geek_range = r'(?:^|(.+?))(?:;(.+?)$|$)' 637 re_geek_range = r'(?:^|(.+?))(?:;(.+?)$|$)'
634 # Check which syntax to use 638 # Check which syntax to use
635 if spec.find(';') == -1: 639 if spec.find(';') == -1:
636 # Native english 640 # Native english
639 # Geek 643 # Geek
640 mch_range = re.search(re_geek_range, spec.strip()) 644 mch_range = re.search(re_geek_range, spec.strip())
641 if mch_range: 645 if mch_range:
642 self.from_value, self.to_value = mch_range.groups() 646 self.from_value, self.to_value = mch_range.groups()
643 if self.from_value: 647 if self.from_value:
644 self.from_value = type(self.from_value.strip(), **params) 648 self.from_value = Type(self.from_value.strip(), **params)
645 if self.to_value: 649 if self.to_value:
646 self.to_value = type(self.to_value.strip(), **params) 650 self.to_value = Type(self.to_value.strip(), **params)
647 else: 651 else:
648 raise ValueError, "Invalid range" 652 raise ValueError, "Invalid range"
649 653
650 def __str__(self): 654 def __str__(self):
651 return "from %s to %s" % (self.from_value, self.to_value) 655 return "from %s to %s" % (self.from_value, self.to_value)

Roundup Issue Tracker: http://roundup-tracker.org/