当前位置: 首页>>代码示例>>Python>>正文


Python Date.parse方法代码示例

本文整理汇总了Python中GTG.tools.dates.Date.parse方法的典型用法代码示例。如果您正苦于以下问题:Python Date.parse方法的具体用法?Python Date.parse怎么用?Python Date.parse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在GTG.tools.dates.Date的用法示例。


在下文中一共展示了Date.parse方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: date_changed

# 需要导入模块: from GTG.tools.dates import Date [as 别名]
# 或者: from GTG.tools.dates.Date import parse [as 别名]
    def date_changed(self, widget, data):
        try:
            if data == GTGCalendar.DATE_KIND_ENDON:
                if Date.parse(widget.get_text()):
                    if Date.parse(self.startdate_widget.get_text()).__gt__(
                        Date.parse(widget.get_text())):
                        valid = False
                    else:
                        valid = True
            else:
                Date.parse(widget.get_text())
                valid = True
        except ValueError:
            valid = False

        if valid:
            # If the date is valid, we write with default color in the widget
            # "none" will set the default color.
            widget.override_color(Gtk.StateType.NORMAL, None)
            widget.override_background_color(Gtk.StateType.NORMAL, None)
        else:
            #We should write in red in the entry if the date is not valid
            text_color = Gdk.RGBA()
            text_color.parse("#F00")
            widget.override_color(Gtk.StateType.NORMAL, text_color)

            bg_color = Gdk.RGBA()
            bg_color.parse("#F88")
            widget.override_background_color(Gtk.StateType.NORMAL, bg_color)
开发者ID:sagarghuge,项目名称:recurringtask,代码行数:31,代码来源:editor.py

示例2: test_parse_fuzzy_dates

# 需要导入模块: from GTG.tools.dates import Date [as 别名]
# 或者: from GTG.tools.dates.Date import parse [as 别名]
 def test_parse_fuzzy_dates(self):
     """ Parse fuzzy dates like now, soon, later, someday """
     self.assertEqual(Date.parse("now"), Date.now())
     self.assertEqual(Date.parse("soon"), Date.soon())
     self.assertEqual(Date.parse("later"), Date.someday())
     self.assertEqual(Date.parse("someday"), Date.someday())
     self.assertEqual(Date.parse(""), Date.no_date())
开发者ID:lefred,项目名称:backend_gtgonline,代码行数:9,代码来源:test_dates.py

示例3: test_parse_fuzzy_dates_str

# 需要导入模块: from GTG.tools.dates import Date [as 别名]
# 或者: from GTG.tools.dates.Date import parse [as 别名]
 def test_parse_fuzzy_dates_str(self):
     """ Print fuzzy dates in localized version """
     self.assertEqual(str(Date.parse("now")), _("now"))
     self.assertEqual(str(Date.parse("soon")), _("soon"))
     self.assertEqual(str(Date.parse("later")), _("someday"))
     self.assertEqual(str(Date.parse("someday")), _("someday"))
     self.assertEqual(str(Date.parse("")), "")
开发者ID:lefred,项目名称:backend_gtgonline,代码行数:9,代码来源:test_dates.py

示例4: test_parse_local_fuzzy_dates

# 需要导入模块: from GTG.tools.dates import Date [as 别名]
# 或者: from GTG.tools.dates.Date import parse [as 别名]
 def test_parse_local_fuzzy_dates(self):
     """ Parse fuzzy dates in their localized version """
     self.assertEqual(Date.parse(_("now")), Date.now())
     self.assertEqual(Date.parse(_("soon")), Date.soon())
     self.assertEqual(Date.parse(_("later")), Date.someday())
     self.assertEqual(Date.parse(_("someday")), Date.someday())
     self.assertEqual(Date.parse(""), Date.no_date())
开发者ID:lefred,项目名称:backend_gtgonline,代码行数:9,代码来源:test_dates.py

示例5: test_parse_dates

# 需要导入模块: from GTG.tools.dates import Date [as 别名]
# 或者: from GTG.tools.dates.Date import parse [as 别名]
    def test_parse_dates(self):
        """ Parse common numeric date """
        self.assertEqual(str(Date.parse("1985-03-29")), "1985-03-29")
        self.assertEqual(str(Date.parse("19850329")), "1985-03-29")
        self.assertEqual(str(Date.parse("1985/03/29")), "1985-03-29")

        today = date.today()
        parse_string = "%02d%02d" % (today.month, today.day)
        self.assertEqual(Date.parse(parse_string), today)
开发者ID:lefred,项目名称:backend_gtgonline,代码行数:11,代码来源:test_dates.py

示例6: set_complex_title

# 需要导入模块: from GTG.tools.dates import Date [as 别名]
# 或者: from GTG.tools.dates.Date import parse [as 别名]
    def set_complex_title(self, text, tags=[]):
        if tags:
            assert(isinstance(tags[0], str))
        due_date = Date.no_date()
        defer_date = Date.no_date()
        if text:
            # Get tags in the title
            for match in extract_tags_from_text(text):
                tags.append(match)
            # Get attributes
            regexp = r'([\s]*)([\w-]+):\s*([^\s]+)'
            matches = re.findall(regexp, text, re.UNICODE)
            for spaces, attribute, args in matches:
                valid_attribute = True
                if attribute.lower() in ["tags", _("tags"), "tag", _("tag")]:
                    for tag in args.split(","):
                        if not tag.strip() == "@" and not tag.strip() == "":
                            if not tag.startswith("@"):
                                tag = "@" + tag
                            tags.append(tag)
                elif attribute.lower() in ["defer", _("defer"), "start",
                                           _("start")]:
                    try:
                        defer_date = Date.parse(args)
                    except ValueError:
                        valid_attribute = False
                elif attribute.lower() == "due" or \
                        attribute.lower() == _("due"):
                    try:
                        due_date = Date.parse(args)
                    except:
                        valid_attribute = False
                else:
                    # attribute is unknown
                    valid_attribute = False

                if valid_attribute:
                    # remove valid attribute from the task title
                    text = \
                        text.replace("%s%s:%s" % (spaces, attribute, args), "")

            for t in tags:
                self.add_tag(t)

            if text != "":
                self.set_title(text.strip())
                self.set_to_keep()

            self.set_due_date(due_date)
            self.set_start_date(defer_date)
开发者ID:kunaaljain,项目名称:gtg,代码行数:52,代码来源:task.py

示例7: task_from_xml

# 需要导入模块: from GTG.tools.dates import Date [as 别名]
# 或者: from GTG.tools.dates.Date import parse [as 别名]
def task_from_xml(task, xmlnode):
    # print "********************************"
    # print xmlnode.toprettyxml()

    task.set_uuid(xmlnode.getAttribute("uuid"))
    task.set_title(read_node(xmlnode, "title"))

    status = xmlnode.getAttribute("status")
    donedate = Date.parse(read_node(xmlnode, "donedate"))
    task.set_status(status, donedate=donedate)

    duedate = Date(read_node(xmlnode, "duedate"))
    task.set_due_date(duedate)

    startdate = Date(read_node(xmlnode, "startdate"))
    task.set_start_date(startdate)

    modified = read_node(xmlnode, "modified")
    if modified != "":
        modified = datetime.strptime(modified, "%Y-%m-%dT%H:%M:%S")
        task.set_modified(modified)

    tags = xmlnode.getAttribute("tags").replace(" ", "")
    tags = (tag for tag in tags.split(",") if tag.strip() != "")
    for tag in tags:
        # FIXME why unescape????
        task.tag_added(saxutils.unescape(tag))

    # FIXME why we need to convert that through an XML?
    content = read_node(xmlnode, "content")
    if content != "":
        content = "<content>%s</content>" % content
        content = minidom.parseString(content).firstChild.toxml()
        task.set_text(content)

    for subtask in xmlnode.getElementsByTagName("subtask"):
        task.add_child(get_text(subtask))

    for attr in xmlnode.getElementsByTagName("attribute"):
        if len(attr.childNodes) > 0:
            value = get_text(attr)
        else:
            value = ""
        key = attr.getAttribute("key")
        namespace = attr.getAttribute("namespace")
        task.set_attribute(key, value, namespace=namespace)

    # FIXME do we need remote task ids? I don't think so
    # FIXME if so => rework them into a more usable structure!!!
    #                (like attributes)
    # REMOTE TASK IDS
    remote_ids_list = xmlnode.getElementsByTagName("task-remote-ids")
    for remote_id in remote_ids_list:
        if remote_id.childNodes:
            node = remote_id.childNodes[0]
            backend_id = node.firstChild.nodeValue
            remote_task_id = node.childNodes[1].firstChild.nodeValue
            task.add_remote_id(backend_id, remote_task_id)

    return task
开发者ID:parinporecha,项目名称:backend_gtgonline,代码行数:62,代码来源:taskxml.py

示例8: date_changed

# 需要导入模块: from GTG.tools.dates import Date [as 别名]
# 或者: from GTG.tools.dates.Date import parse [as 别名]
    def date_changed(self, widget, data):
        try:
            Date.parse(widget.get_text())
            valid = True
        except ValueError:
            valid = False

        if valid:
            # If the date is valid, we write with default color in the widget
            # "none" will set the default color.
            widget.modify_text(gtk.STATE_NORMAL, None)
            widget.modify_base(gtk.STATE_NORMAL, None)
        else:
            # We should write in red in the entry if the date is not valid
            widget.modify_text(gtk.STATE_NORMAL, gtk.gdk.color_parse("#F00"))
            widget.modify_base(gtk.STATE_NORMAL, gtk.gdk.color_parse("#F88"))
开发者ID:lefred,项目名称:backend_gtgonline,代码行数:18,代码来源:editor.py

示例9: refresh_date_field

# 需要导入模块: from GTG.tools.dates import Date [as 别名]
# 或者: from GTG.tools.dates.Date import parse [as 别名]
 def refresh_date_field(self, date, field):
     try:
         prevdate = Date.parse(field.get_text())
         update_date = date != prevdate
     except ValueError:
         update_date = True
     if update_date:
         field.set_text(str(date))
开发者ID:sagarghuge,项目名称:recurringtask,代码行数:10,代码来源:editor.py

示例10: test_missing_year_next_year

# 需要导入模块: from GTG.tools.dates import Date [as 别名]
# 或者: from GTG.tools.dates.Date import parse [as 别名]
    def test_missing_year_next_year(self):
        """ Parsing %m%d have to find correct date:
        we enter a day the next year """
        aday = date.today()
        if aday.day == 1 and aday.month == 1:
            # not possible to add a day next year
            return

        aday = aday.replace(year=aday.year + 1, month=1, day=1)
        self.assertEqual(Date.parse("0101"), aday)
开发者ID:lefred,项目名称:backend_gtgonline,代码行数:12,代码来源:test_dates.py

示例11: calculate_new_due_date

# 需要导入模块: from GTG.tools.dates import Date [as 别名]
# 或者: from GTG.tools.dates.Date import parse [as 别名]
 def calculate_new_due_date(self):
     if self.repeats == "Daily":
         if int(self.frequency) == 0:
             return self.get_due_date() + \
                 timedelta(days=1)
         else:
             return self.get_due_date() + \
                 timedelta(days=int(self.frequency))
     elif self.repeats == "Weekly":
         current_date = self.get_current_date()
         rule_tupple = self.create_weekdayrule_tuple()
         if int(self.frequency) == 0 or int(self.frequency) == 1:
             new_date = list(rrule.rrule(rrule.WEEKLY, count=1,
                 wkst=current_date.weekday(),
                 byweekday=rule_tupple,
                 dtstart=datetime(
                 self.due_date.year,self.due_date.month,self.due_date.day+1)))[0]
             return Date.parse(
                 str(new_date.year)+str(new_date.month)+str(new_date.day))
         else:
             new_date = list(rrule.rrule(rrule.WEEKLY,
                 interval=int(self.frequency),count=1,
                 wkst=current_date.weekday(),
                 byweekday=rule_tupple,
                 dtstart=datetime(
                 self.due_date.year,self.due_date.month,self.due_date.day+1)))[0]
             return Date.parse(
                 str(new_date.year)+str(new_date.month)+str(new_date.day))
     elif self.repeats == "Monthly":
         if int(self.frequency) == 0 or int(self.frequency) == 1:
             new_date = self.get_monthly_due_date(1)
             return Date.parse(
                 str(new_date.year)+str(new_date.month)+str(new_date.day))
         else:
             new_date = self.get_monthly_due_date(int(self.frequency))
             return Date.parse(
                 str(new_date.year)+str(new_date.month)+str(new_date.day))
     elif self.repeats == "Yearly":
         if int(self.frequency) == 0:
             return self.add_months(self.due_date(), 12)
         else:
             return self.add_months(
                 self.get_due_date(), 12 * int(self.frequency))
开发者ID:sagarghuge,项目名称:recurringtask,代码行数:45,代码来源:task.py

示例12: test_on_certain_day

# 需要导入模块: from GTG.tools.dates import Date [as 别名]
# 或者: from GTG.tools.dates.Date import parse [as 别名]
    def test_on_certain_day(self):
        """ Parse due:3 as 3rd day this month or next month
        if it is already more or already 3rd day """
        for i in range(28):
            i += 1
            aday = date.today()
            if i <= aday.day:
                aday = next_month(aday, i)
            else:
                aday = aday.replace(day=i)

            self.assertEqual(Date.parse(str(i)), aday)
开发者ID:lefred,项目名称:backend_gtgonline,代码行数:14,代码来源:test_dates.py

示例13: ModifyTask

# 需要导入模块: from GTG.tools.dates import Date [as 别名]
# 或者: from GTG.tools.dates.Date import parse [as 别名]
    def ModifyTask(self, tid, task_data):
        """
        Updates the task with ID tid using the provided information
        in the task_data structure.  Note that any fields left blank
        or undefined in task_data will clear the value in the task,
        so the best way to update a task is to first retrieve it via
        get_task(tid), modify entries as desired, and send it back
        via this function.
        """
        task = self.req.get_task(tid)
        task.set_status(task_data["status"],
                        donedate=Date.parse(task_data["donedate"]))
        task.set_title(task_data["title"])
        task.set_due_date(Date.parse(task_data["duedate"]))
        task.set_start_date(Date.parse(task_data["startdate"]))
        task.set_text(task_data["text"])

        for tag in task_data["tags"]:
            task.add_tag(tag)
        for sub in task_data["subtask"]:
            task.add_child(sub)
        return task_to_dict(task)
开发者ID:lefred,项目名称:backend_gtgonline,代码行数:24,代码来源:dbuswrapper.py

示例14: date_focus_out

# 需要导入模块: from GTG.tools.dates import Date [as 别名]
# 或者: from GTG.tools.dates.Date import parse [as 别名]
    def date_focus_out(self, widget, event, date_kind):
        try:
            datetoset = Date.parse(widget.get_text())
        except ValueError:
            datetoset = None

        if datetoset is not None:
            if date_kind == GTGCalendar.DATE_KIND_START:
                self.task.set_start_date(datetoset)
            elif date_kind == GTGCalendar.DATE_KIND_DUE:
                self.task.set_due_date(datetoset)
            elif date_kind == GTGCalendar.DATE_KIND_CLOSED:
                self.task.set_closed_date(datetoset)
            self.refresh_editor()
开发者ID:kunaaljain,项目名称:gtg,代码行数:16,代码来源:editor.py

示例15: date_focus_out

# 需要导入模块: from GTG.tools.dates import Date [as 别名]
# 或者: from GTG.tools.dates.Date import parse [as 别名]
    def date_focus_out(self, widget, event, data):
        try:
            datetoset = Date.parse(widget.get_text())
        except ValueError:
            datetoset = None

        if datetoset is not None:
            if data == "start":
                self.task.set_start_date(datetoset)
            elif data == "due":
                self.task.set_due_date(datetoset)
            elif data == "closed":
                self.task.set_closed_date(datetoset)
            self.refresh_editor()
开发者ID:lefred,项目名称:backend_gtgonline,代码行数:16,代码来源:editor.py


注:本文中的GTG.tools.dates.Date.parse方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。