fix: allow to import time field (#17677)
This commit is contained in:
parent
9485c31f16
commit
c478673367
2 changed files with 19 additions and 6 deletions
|
|
@ -6,7 +6,7 @@ import json
|
|||
import os
|
||||
import re
|
||||
import timeit
|
||||
from datetime import date, datetime
|
||||
from datetime import date, datetime, time
|
||||
|
||||
import frappe
|
||||
from frappe import _
|
||||
|
|
@ -937,11 +937,13 @@ class Column:
|
|||
"""
|
||||
|
||||
def guess_date_format(d):
|
||||
if isinstance(d, (datetime, date)):
|
||||
if isinstance(d, (datetime, date, time)):
|
||||
if self.df.fieldtype == "Date":
|
||||
return "%Y-%m-%d"
|
||||
if self.df.fieldtype == "Datetime":
|
||||
return "%Y-%m-%d %H:%M:%S"
|
||||
if self.df.fieldtype == "Time":
|
||||
return "%H:%M:%S"
|
||||
if isinstance(d, str):
|
||||
return frappe.utils.guess_date_format(d)
|
||||
|
||||
|
|
@ -994,16 +996,22 @@ class Column:
|
|||
}
|
||||
)
|
||||
elif self.df.fieldtype in ("Date", "Time", "Datetime"):
|
||||
# guess date format
|
||||
# guess date/time format
|
||||
self.date_format = self.guess_date_format_for_column()
|
||||
if not self.date_format:
|
||||
self.date_format = "%Y-%m-%d"
|
||||
if self.df.fieldtype == "Time":
|
||||
self.date_format = "%H:%M:%S"
|
||||
format = "HH:mm:ss"
|
||||
else:
|
||||
self.date_format = "%Y-%m-%d"
|
||||
format = "yyyy-mm-dd"
|
||||
|
||||
self.warnings.append(
|
||||
{
|
||||
"col": self.column_number,
|
||||
"message": _(
|
||||
"Date format could not be determined from the values in this column. Defaulting to yyyy-mm-dd."
|
||||
),
|
||||
"{0} format could not be determined from the values in this column. Defaulting to {1}."
|
||||
).format(self.df.fieldtype, format),
|
||||
"type": "info",
|
||||
}
|
||||
)
|
||||
|
|
|
|||
|
|
@ -2024,6 +2024,11 @@ def guess_date_format(date_string: str) -> str:
|
|||
if date_format:
|
||||
return date_format
|
||||
|
||||
# check if time format can be guessed
|
||||
time_format = _get_time_format(date_string)
|
||||
if time_format:
|
||||
return time_format
|
||||
|
||||
# date_string doesnt look like date, it can have a time part too
|
||||
# split the date string into date and time parts
|
||||
if " " in date_string:
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue