|
@@ -231,7 +231,7 @@ def get_datetime_str(datetime_obj): |
|
|
|
|
|
|
|
|
return datetime_obj.strftime('%Y-%m-%d %H:%M:%S.%f') |
|
|
return datetime_obj.strftime('%Y-%m-%d %H:%M:%S.%f') |
|
|
|
|
|
|
|
|
def formatdate(string_date=None): |
|
|
|
|
|
|
|
|
def formatdate(string_date=None, format_string=None): |
|
|
""" |
|
|
""" |
|
|
Convers the given string date to :data:`user_format` |
|
|
Convers the given string date to :data:`user_format` |
|
|
User format specified in defaults |
|
|
User format specified in defaults |
|
@@ -242,28 +242,25 @@ def formatdate(string_date=None): |
|
|
* mm-dd-yyyy |
|
|
* mm-dd-yyyy |
|
|
* dd/mm/yyyy |
|
|
* dd/mm/yyyy |
|
|
""" |
|
|
""" |
|
|
if string_date: |
|
|
|
|
|
string_date = getdate(string_date) |
|
|
|
|
|
else: |
|
|
|
|
|
string_date = now_datetime().date() |
|
|
|
|
|
|
|
|
date = getdate(string_date) if string_date else now_datetime().date() |
|
|
|
|
|
|
|
|
if getattr(frappe.local, "user_format", None) is None: |
|
|
|
|
|
frappe.local.user_format = frappe.db.get_default("date_format") |
|
|
|
|
|
|
|
|
if format_string: |
|
|
|
|
|
return babel.dates.format_date(date, format_string or "medium", locale=(frappe.local.lang or "").replace("-", "_")) |
|
|
|
|
|
else: |
|
|
|
|
|
if getattr(frappe.local, "user_format", None) is None: |
|
|
|
|
|
frappe.local.user_format = frappe.db.get_default("date_format") |
|
|
|
|
|
|
|
|
out = frappe.local.user_format |
|
|
|
|
|
|
|
|
out = frappe.local.user_format |
|
|
|
|
|
|
|
|
return out.replace("dd", string_date.strftime("%d"))\ |
|
|
|
|
|
.replace("mm", string_date.strftime("%m"))\ |
|
|
|
|
|
.replace("yyyy", string_date.strftime("%Y")) |
|
|
|
|
|
|
|
|
return out.replace("dd", date.strftime("%d"))\ |
|
|
|
|
|
.replace("mm", date.strftime("%m"))\ |
|
|
|
|
|
.replace("yyyy", date.strftime("%Y")) |
|
|
|
|
|
|
|
|
def global_date_format(date): |
|
|
def global_date_format(date): |
|
|
"""returns date as 1 January 2012""" |
|
|
"""returns date as 1 January 2012""" |
|
|
formatted_date = getdate(date).strftime("%d %B %Y") |
|
|
formatted_date = getdate(date).strftime("%d %B %Y") |
|
|
return formatted_date.startswith("0") and formatted_date[1:] or formatted_date |
|
|
return formatted_date.startswith("0") and formatted_date[1:] or formatted_date |
|
|
|
|
|
|
|
|
def localize_date(date, format_string=None, locale=None): |
|
|
|
|
|
return babel.dates.format_date(date, format_string or "medium", locale=locale or (frappe.local.lang or "").replace("-", "_")) |
|
|
|
|
|
|
|
|
|
|
|
def dict_to_str(args, sep='&'): |
|
|
def dict_to_str(args, sep='&'): |
|
|
""" |
|
|
""" |
|
|
Converts a dictionary to URL |
|
|
Converts a dictionary to URL |
|
|