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.dateformatter import GregorianDateFormatter 20 21 22 REGION_START_POS = 0 23 REGION_LENGTH = 1 24 REGION_SEPARATOR = 2 25 REGION_TYPE = 3 26 YEAR = GregorianDateFormatter.YEAR 27 MONTH = GregorianDateFormatter.MONTH 28 DAY = GregorianDateFormatter.DAY 29 ERROR_TEXT = _("""\ 30 Invalid Date Format: 31 32 The format should contain 33 one year placeholder = yyyy 34 one month placeholder = mmm or mm 35 one day placeholder = dd 36 two placeholders for separators between year, month and day 37 38 Separators can't contain the letters y, m or d 39 40 Example of valid formats: 41 yyyy-mm-dd 42 dd/mm/yyyy 43 mmm/dd-yyyy 44 """) 45 4648112 11550 return ERROR_TEXT51 58 62 6567 return (self._get_region_type_index(YEAR), self._get_region_type_index(MONTH), self._get_region_type_index(DAY))6870 for i in range(len(self.regions)): 71 if self.regions[i][REGION_TYPE] == MONTH: 72 return self.regions[i][REGION_LENGTH] == 3 73 return False7476 for i in range(len(self.regions)): 77 if self.regions[i][REGION_TYPE] == region_type: 78 return i7981 fmt = date_format.lower() 82 self._assert_leading_char_is_a_date_placeholder(date_format) 83 self._assert_trailing_char_is_a_date_placeholder(date_format) 84 fmt, regions = self._get_regions(fmt, date_format) 85 self._get_separators_placeholders(fmt, regions) 86 return regions87 91 9597 separator1_length = regions[1][REGION_START_POS] - regions[0][REGION_LENGTH] 98 regions[1][REGION_SEPARATOR] = fmt[:separator1_length] 99 regions[2][REGION_SEPARATOR] = fmt[separator1_length:]100 104 fmt, region0 = self._get_and_remove_year_region(fmt, date_format) 105 fmt, region1 = self._get_and_remove_month_region(fmt, date_format) 106 fmt, region2 = self._get_and_remove_day_region(fmt, date_format) 107 regions = [region0, region1, region2] 108 if "y" in fmt or "m" in fmt or "d" in fmt: 109 raise ValueError() 110 regions.sort(key=getKey) 111 return fmt, regions117 if "mmm" in fmt: 118 return self._get_and_remove_region(fmt, date_format, "mmm", MONTH) 119 elif "mm" in fmt: 120 return self._get_and_remove_region(fmt, date_format, "mm", MONTH) 121 else: 122 raise ValueError()123 126128 if placeholder in fmt: 129 fmt = fmt.replace(placeholder, "", 1) 130 index = date_format.lower().index(placeholder) 131 return fmt, [index, len(placeholder), "", region_type] 132 else: 133 raise ValueError()134
Home | Trees | Indices | Help |
|
---|
Generated by Epydoc 3.0.1 on Sun Jul 28 01:55:29 2019 | http://epydoc.sourceforge.net |