瀏覽代碼

[fix] cast time string to timedelta

version-14
Anand Doshi 10 年之前
父節點
當前提交
9cc9f5ab15
共有 2 個文件被更改,包括 11 次插入1 次删除
  1. +4
    -1
      frappe/model/base_document.py
  2. +7
    -0
      frappe/utils/data.py

+ 4
- 1
frappe/model/base_document.py 查看文件

@@ -4,7 +4,7 @@
from __future__ import unicode_literals from __future__ import unicode_literals
import frappe, sys import frappe, sys
from frappe import _ from frappe import _
from frappe.utils import cint, flt, now, cstr, strip_html, getdate, get_datetime
from frappe.utils import cint, flt, now, cstr, strip_html, getdate, get_datetime, to_timedelta
from frappe.model import default_fields from frappe.model import default_fields
from frappe.model.naming import set_new_name from frappe.model.naming import set_new_name
from frappe.modules import load_doctype_module from frappe.modules import load_doctype_module
@@ -539,6 +539,9 @@ class BaseDocument(object):
elif df.fieldtype == "Datetime": elif df.fieldtype == "Datetime":
val = get_datetime(val) val = get_datetime(val)


elif df.fieldtype == "Time":
val = to_timedelta(val)

return val return val


def _extract_images_from_text_editor(self): def _extract_images_from_text_editor(self):


+ 7
- 0
frappe/utils/data.py 查看文件

@@ -54,6 +54,13 @@ def get_datetime(datetime_str=None):


return parser.parse(datetime_str) return parser.parse(datetime_str)


def to_timedelta(time_str):
if isinstance(time_str, basestring):
t = parser.parse(time_str)
return datetime.timedelta(hours=t.hour, minutes=t.minute, seconds=t.second)

else:
return time_str


def add_to_date(date, years=0, months=0, days=0): def add_to_date(date, years=0, months=0, days=0):
"""Adds `days` to the given date""" """Adds `days` to the given date"""


Loading…
取消
儲存