本文整理汇总了Python中topydo.lib.RelativeDate.relative_date_to_date函数的典型用法代码示例。如果您正苦于以下问题:Python relative_date_to_date函数的具体用法?Python relative_date_to_date怎么用?Python relative_date_to_date使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了relative_date_to_date函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: match
def match(self, p_todo):
"""
Performs a match on a key:value tag in the todo.
First it tries to convert the value and the user-entered expression to
a date and makes a comparison if it succeeds, based on the given
operator (default ==).
Upon failure, it falls back to converting value and user-entered
expression to an integer and makes a numerical comparison based on the
given operator (default ==)
As a last resort, it falls back to using a Grep filter to see if the
user given expression is contained in the todo text.
"""
if not self.key or not p_todo.has_tag(self.key):
return False
try:
operand1 = date_string_to_date(p_todo.tag_value(self.key))
operand2 = relative_date_to_date(self.value)
if not operand2:
operand2 = date_string_to_date(self.value)
except ValueError:
operand1 = p_todo.tag_value(self.key)
operand2 = self.value
try:
operand1 = int(operand1)
operand2 = int(operand2)
except ValueError:
grep = GrepFilter(self.expression)
return grep.match(p_todo)
return self.compare_operands(operand1, operand2)
开发者ID:rameshg87,项目名称:topydo,代码行数:35,代码来源:Filter.py
示例2: convert_date
def convert_date(p_tag):
value = p_todo.tag_value(p_tag)
if value:
dateobj = relative_date_to_date(value)
if dateobj:
p_todo.set_tag(p_tag, dateobj.isoformat())
开发者ID:rtvb,项目名称:topydo,代码行数:7,代码来源:AddCommand.py
示例3: _advance_recurring_todo_helper
def _advance_recurring_todo_helper(p_todo, p_offset):
"""
Given a Todo item, return a new instance of a Todo item with the dates
shifted according to the recurrence rule.
The new date is calculated from the given p_offset value.
When no recurrence tag is present, an exception is raised.
"""
todo = Todo(p_todo.source())
pattern = todo.tag_value('rec')
if not pattern:
raise NoRecurrenceException()
length = todo.length()
new_due = relative_date_to_date(pattern, p_offset)
if not new_due:
raise NoRecurrenceException()
# pylint: disable=E1103
todo.set_tag(config().tag_due(), new_due.isoformat())
if todo.start_date():
new_start = new_due - timedelta(length)
todo.set_tag(config().tag_start(), new_start.isoformat())
todo.set_creation_date(date.today())
return todo
开发者ID:netimen,项目名称:topydo,代码行数:32,代码来源:Recurrence.py
示例4: test_weekday_next_week
def test_weekday_next_week(self):
"""
When entering "Friday" on a Friday, return next week Friday instead of
today.
"""
result = relative_date_to_date("fri")
self.assertTrue(result, self.friday)
开发者ID:rameshg87,项目名称:topydo,代码行数:7,代码来源:test_relative_date.py
示例5: _execute_multi_specific
def _execute_multi_specific(self):
def _get_offset(p_todo):
offset = p_todo.tag_value(
config().tag_due(), date.today().isoformat())
offset_date = date_string_to_date(offset)
if offset_date < date.today():
offset_date = date.today()
return offset_date
pattern = self.args[-1]
self.printer.add_filter(PrettyPrinterNumbers(self.todolist))
for todo in self.todos:
offset = _get_offset(todo)
new_due = relative_date_to_date(pattern, offset)
if new_due:
if self.move_start_date and todo.has_tag(config().tag_start()):
length = todo.length()
new_start = new_due - timedelta(length)
# pylint: disable=E1103
todo.set_tag(config().tag_start(), new_start.isoformat())
# pylint: disable=E1103
todo.set_tag(config().tag_due(), new_due.isoformat())
self.todolist.set_dirty()
self.out(self.printer.print_todo(todo))
else:
self.error("Invalid date pattern given.")
break
开发者ID:netimen,项目名称:topydo,代码行数:33,代码来源:PostponeCommand.py
示例6: test_one_month_ext
def test_one_month_ext(self):
test_date1 = date(2015, 1, 29)
test_date2 = date(2016, 1, 31)
test_date3 = date(2015, 12, 31)
test_date4 = date(2015, 7, 31)
test_date5 = date(2015, 10, 31)
result1 = relative_date_to_date('1m', test_date1)
result2 = relative_date_to_date('1m', test_date2)
result3 = relative_date_to_date('1m', test_date3)
result4 = relative_date_to_date('1m', test_date4)
result5 = relative_date_to_date('1m', test_date5)
self.assertEqual(result1, date(2015, 2, 28))
self.assertEqual(result2, date(2016, 2, 29))
self.assertEqual(result3, date(2016, 1, 31))
self.assertEqual(result4, date(2015, 8, 31))
self.assertEqual(result5, date(2015, 11, 30))
开发者ID:rameshg87,项目名称:topydo,代码行数:18,代码来源:test_relative_date.py
示例7: _convert_relative_dates
def _convert_relative_dates(self):
is_start_tag = self.tag == config().tag_start()
is_due_tag = self.tag == config().tag_due()
if self.relative_date or is_start_tag or is_due_tag:
real_date = relative_date_to_date(self.value)
if real_date:
self.value = real_date.isoformat()
开发者ID:bram85,项目名称:topydo,代码行数:9,代码来源:TagCommand.py
示例8: _dates
def _dates(self, p_word_before_cursor):
to_absolute = lambda s: relative_date_to_date(s).isoformat()
start_value_pos = p_word_before_cursor.find(':') + 1
value = p_word_before_cursor[start_value_pos:]
for reldate in _date_suggestions():
if not reldate.startswith(value):
continue
yield Completion(reldate, -len(value), display_meta=to_absolute(reldate))
开发者ID:netimen,项目名称:topydo,代码行数:11,代码来源:TopydoCompleter.py
示例9: process_flag
def process_flag(self, p_opt, p_value):
super().process_flag(p_opt, p_value)
if p_opt == "-s" or p_opt == "--strict":
self.strict_recurrence = True
elif p_opt == "-d" or p_opt == "--date":
try:
self.completion_date = relative_date_to_date(p_value)
if not self.completion_date:
self.completion_date = date_string_to_date(p_value)
except ValueError:
self.completion_date = date.today()
开发者ID:rtvb,项目名称:topydo,代码行数:13,代码来源:DoCommand.py
示例10: advance_recurring_todo
def advance_recurring_todo(p_todo, p_offset=None, p_strict=False):
"""
Given a Todo item, return a new instance of a Todo item with the dates
shifted according to the recurrence rule.
Strict means that the real due date is taken as a offset, not today or a
future date to determine the offset.
When the todo item has no due date, then the date is used passed by the
caller (defaulting to today).
When no recurrence tag is present, an exception is raised.
"""
todo = Todo(p_todo.source())
pattern = todo.tag_value('rec')
if not pattern:
raise NoRecurrenceException()
elif pattern.startswith('+'):
p_strict = True
# strip off the +
pattern = pattern[1:]
if p_strict:
offset = p_todo.due_date() or p_offset or date.today()
else:
offset = p_offset or date.today()
length = todo.length()
new_due = relative_date_to_date(pattern, offset)
if not new_due:
raise NoRecurrenceException()
# pylint: disable=E1103
todo.set_tag(config().tag_due(), new_due.isoformat())
if todo.start_date():
new_start = new_due - timedelta(length)
todo.set_tag(config().tag_start(), new_start.isoformat())
todo.set_creation_date(date.today())
return todo
开发者ID:MinchinWeb,项目名称:topydo,代码行数:44,代码来源:Recurrence.py
示例11: _dates
def _dates(p_word_before_cursor):
""" Generator for date completion. """
def _date_suggestions():
"""
Returns a list of relative date that is presented to the user as auto
complete suggestions.
"""
# don't use strftime, prevent locales to kick in
days_of_week = {
0: "Monday",
1: "Tuesday",
2: "Wednesday",
3: "Thursday",
4: "Friday",
5: "Saturday",
6: "Sunday"
}
dates = [
'today',
'tomorrow',
]
# show days of week up to next week
dow = datetime.date.today().weekday()
for i in range(dow + 2 % 7, dow + 7):
dates.append(days_of_week[i % 7])
# and some more relative days starting from next week
dates += ["1w", "2w", "1m", "2m", "3m", "1y"]
return dates
to_absolute = lambda s: relative_date_to_date(s).isoformat()
start_value_pos = p_word_before_cursor.find(':') + 1
value = p_word_before_cursor[start_value_pos:]
for reldate in _date_suggestions():
if not reldate.startswith(value):
continue
yield Completion(reldate, -len(value), display_meta=to_absolute(reldate))
开发者ID:MinchinWeb,项目名称:topydo,代码行数:43,代码来源:TopydoCompleter.py
示例12: test_one_month
def test_one_month(self):
test_date = date(2015, 1, 10)
result = relative_date_to_date('1m', test_date)
self.assertEqual(result, date(2015, 2, 10))
开发者ID:rameshg87,项目名称:topydo,代码行数:4,代码来源:test_relative_date.py
示例13: test_one_week
def test_one_week(self):
result = relative_date_to_date('1w')
self.assertEqual(result, date(2015, 11, 13))
开发者ID:rameshg87,项目名称:topydo,代码行数:3,代码来源:test_relative_date.py
示例14: test_one_bweek
def test_one_bweek(self):
result = relative_date_to_date('5b')
self.assertEqual(result, self.friday)
开发者ID:rameshg87,项目名称:topydo,代码行数:3,代码来源:test_relative_date.py
示例15: test_one_bday
def test_one_bday(self):
result = relative_date_to_date('1b')
self.assertEqual(result, self.monday)
开发者ID:rameshg87,项目名称:topydo,代码行数:3,代码来源:test_relative_date.py
示例16: test_one_day
def test_one_day(self):
result = relative_date_to_date('1d')
self.assertEqual(result, self.tomorrow)
开发者ID:rameshg87,项目名称:topydo,代码行数:3,代码来源:test_relative_date.py
示例17: test_tomorrow2
def test_tomorrow2(self):
result = relative_date_to_date('tom')
self.assertEqual(result, self.tomorrow)
开发者ID:rameshg87,项目名称:topydo,代码行数:3,代码来源:test_relative_date.py
示例18: test_leap_year
def test_leap_year(self):
test_date = date(2016, 2, 29)
result1 = relative_date_to_date('1y', test_date)
result2 = relative_date_to_date('4y', test_date)
self.assertEqual(result1, date(2017, 2, 28))
self.assertEqual(result2, date(2020, 2, 29))
开发者ID:rameshg87,项目名称:topydo,代码行数:6,代码来源:test_relative_date.py
示例19: test_zero_years
def test_zero_years(self):
result = relative_date_to_date('0y')
self.assertEqual(result, self.today)
开发者ID:rameshg87,项目名称:topydo,代码行数:3,代码来源:test_relative_date.py
示例20: test_offset1
def test_offset1(self):
result = relative_date_to_date('1d', self.tomorrow)
self.assertEqual(result, date(2015, 11, 8))
开发者ID:rameshg87,项目名称:topydo,代码行数:3,代码来源:test_relative_date.py
注:本文中的topydo.lib.RelativeDate.relative_date_to_date函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论