Skip to content
Snippets Groups Projects
Commit eb16cd60 authored by anonymous's avatar anonymous
Browse files

fix date handling

parent 821b6677
Branches
Tags
No related merge requests found
......@@ -24,16 +24,19 @@ this.ckan.module('odsh_datepicker', function ($, _)
autoclose: true,
language: 'de',
clearBtn: true,
forceParse: true
forceParse: false
}
var onChange = function (ev)
{
var dateString = $(ev.target).val()
var date = moment(dateString, "DD.MM.YYYY", true)
console.log(date)
var isValid = date.isValid() && (dateString.length == 10)
if (isValid)
{
target.val(date.format(serverFormat));
var serverDate = date.format(serverFormat);
console.log(serverDate)
target.val(serverDate);
}
else
{
......
......@@ -117,7 +117,7 @@ def extend_search_convert_local_to_utc_timestamp(str_timestamp):
return dt+"Z"
def odsh_render_datetime(datetime_, fromIso=True):
date_format='{0.day:02d}.{0.month:02d}.{0.year:4d}'
date_format='{0.day:02d}.{0.month:02d}.{0.year:04d}'
if not datetime_:
return ''
if not re.match(r'\d\d\d\d-\d\d-\d\d', datetime_):
......
......@@ -445,7 +445,7 @@ class OdshPlugin(plugins.SingletonPlugin, DefaultTranslation, DefaultDatasetForm
field = 'extras_' + field
if field in dict_pkg and dict_pkg[field]:
d = parse(dict_pkg[field])
dict_pkg[field] = '{0.year:4d}-{0.month:02d}-{0.day:02d}T00:00:00Z'.format(d)
dict_pkg[field] = '{0.year:04d}-{0.month:02d}-{0.day:02d}T00:00:00Z'.format(d)
# if 'res_format' in dict_pkg:
# dict_pkg['res_format']=[e.lower() for e in dict_pkg['res_format']]
......
......@@ -82,6 +82,8 @@ def _set_value(data, field, value):
def validate_extra_date_new(key, field, data, optional, errors):
value = _extract_value(data, field)
print("DATE", value)
if not value:
if not optional:
errors[field] = 'empty'
......@@ -89,11 +91,15 @@ def validate_extra_date_new(key, field, data, optional, errors):
else:
if re.match(r'\d\d\d\d-\d\d-\d\d', value):
try:
print ("BEOFRE PARSE", value)
dt=parse(value)
print("PARSED DATE", dt)
_set_value(data, field, dt.isoformat())
return
except ValueError:
print('ERROR from Exception')
pass
print('ERROR')
errors[field] = 'not a valid date'
def validate_licenseAttributionByText(key, data, errors,context):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment