Home | Trees | Indices | Help |
|
---|
|
1 # Copyright (C) 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018 Rickard Lindberg, Roger Lindberg 2 # 3 # This file is part of Timeline. 4 # 5 # Timeline is free software: you can redistribute it and/or modify 6 # it under the terms of the GNU General Public License as published by 7 # the Free Software Foundation, either version 3 of the License, or 8 # (at your option) any later version. 9 # 10 # Timeline is distributed in the hope that it will be useful, 11 # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 # GNU General Public License for more details. 14 # 15 # You should have received a copy of the GNU General Public License 16 # along with Timeline. If not, see <http://www.gnu.org/licenses/>. 17 18 19 from timelinelib.calendar.gregorian.gregorian import days_in_month 20 from timelinelib.calendar.gregorian.monthnames import abbreviated_name_of_month 21 from timelinelib.calendar.gregorian.monthnames import month_of_abbreviated_name 22 2325 26 YEAR = "YEAR" 27 MONTH = "MONTH" 28 DAY = "DAY" 2919631 self.set_separators("-", "-") 32 self.set_region_order(year=0, month=1, day=2) 33 self.use_abbreviated_name_for_month(False)3436 self._use_abbreviated_name_for_month = value3739 if not first or not second: 40 raise ValueError("Can not set empty separator.") 41 self._first_separator = first 42 self._second_separator = second4345 if set([year, month, day]) != set([0, 1, 2]): 46 raise ValueError("Invalid region order. Must be a combination of 0, 1, and 2.") 47 self._year_position = year 48 self._month_position = month 49 self._day_position = day5052 (year, month, day) = ymd_tuple 53 return (self._format_date(year, month, day), self._is_bc(year))5456 (date, is_bc) = date_bc_tuple 57 regions = self._split(date) 58 year = self._parse_year(regions[self._year_position], is_bc) 59 month = self._parse_month(regions[self._month_position]) 60 day = self._parse_day(regions[self._day_position], year, month) 61 return (year, month, day)6264 return { 65 self._year_position: self.YEAR, 66 self._month_position: self.MONTH, 67 self._day_position: self.DAY, 68 }[self._get_region(date_string, cursor_position)]6971 if cursor_position < self._get_region_start(date_string, 1): 72 return 0 73 elif cursor_position < self._get_region_start(date_string, 2): 74 return 1 75 else: 76 return 27779 region_1 = region_2 = region_3 = '' 80 try: 81 (region_1, region_2) = date_string.split(self._first_separator, 1) 82 (region_2, region_3) = region_2.split(self._second_separator, 1) 83 except ValueError: 84 pass 85 return [ 86 region_1, 87 region_2, 88 region_3, 89 ]9092 if self._cursor_at_end_of_string(date_string, cursor_position): 93 return None 94 for region in [1, 2]: 95 if cursor_position < self._get_region_start(date_string, region): 96 return self._get_region_selection(date_string, region) 97 return None98 101103 for region in [1, 0]: 104 if cursor_position > self._get_region_end(date_string, region): 105 return self._get_region_selection(date_string, region) 106 return None107109 return (self._get_region_start(date_string, which_region), 110 self._get_region_len(date_string, which_region))111 114116 part_delimiter = { 117 0: 0, 118 1: 2, 119 2: 4, 120 }[which_region] 121 return len("".join(self._get_all_parts(date_string)[:part_delimiter]))122124 part_delimiter = { 125 0: 1, 126 1: 3, 127 2: 5, 128 }[which_region] 129 return len("".join(self._get_all_parts(date_string)[:part_delimiter]))130132 regions = self._split(date_string) 133 return [ 134 regions[0], 135 self._first_separator, 136 regions[1], 137 self._second_separator, 138 regions[2], 139 ]140142 regions = { 143 self._year_position: self._format_year(year), 144 self._month_position: self._format_month(month), 145 self._day_position: self._format_day(day), 146 } 147 return "".join([ 148 regions[0], 149 self._first_separator, 150 regions[1], 151 self._second_separator, 152 regions[2], 153 ])154156 if self._is_bc(year): 157 new_year = 1 - year 158 else: 159 new_year = year 160 return "%04d" % new_year161 164 170172 if self._use_abbreviated_name_for_month: 173 return abbreviated_name_of_month(month) 174 else: 175 return "%02d" % month176178 if self._use_abbreviated_name_for_month: 179 return month_of_abbreviated_name(month_string) 180 else: 181 month = int(month_string) 182 if month - 1 in range(12): 183 return month 184 else: 185 raise ValueError("Invalid month")186 189191 day = int(day_string) 192 if day - 1 in range(days_in_month(year, month)): 193 return day 194 else: 195 raise ValueError("Invalid day")
Home | Trees | Indices | Help |
|
---|
Generated by Epydoc 3.0.1 on Sun Jul 28 01:55:29 2019 | http://epydoc.sourceforge.net |