Fixed now() selector (was with - timezone).

This commit is contained in:
Martin Edenhofer 2015-02-05 00:34:32 +01:00
parent d5102c87b1
commit 0843ea52be
2 changed files with 87 additions and 5 deletions

View file

@ -320,12 +320,13 @@ class App.ControllerForm extends App.Controller
number number
if !reset && (year isnt '' && month isnt '' && day isnt '') if !reset && (year isnt '' && month isnt '' && day isnt '')
time = new Date( Date.parse( "#{year}-#{format(month)}-#{format(day)}T00:00:00Z" ) ) time = new Date( Date.parse( "#{year}-#{format(month)}-#{format(day)}T00:00:00Z" ) )
time.setMinutes( time.getMinutes() + diff + time.getTimezoneOffset() )
else else
time = new Date() time = new Date()
#time.setMinutes( time.getMinutes() + diff + time.getTimezoneOffset() ) time.setMinutes( time.getMinutes() + diff )
item.closest('.form-group').find("[name=\"{date}#{name}___day\"]").val( time.getUTCDate() ) item.closest('.form-group').find("[name=\"{date}#{name}___day\"]").val( time.getDate() )
item.closest('.form-group').find("[name=\"{date}#{name}___month\"]").val( time.getUTCMonth()+1 ) item.closest('.form-group').find("[name=\"{date}#{name}___month\"]").val( time.getMonth()+1 )
item.closest('.form-group').find("[name=\"{date}#{name}___year\"]").val( time.getUTCFullYear() ) item.closest('.form-group').find("[name=\"{date}#{name}___year\"]").val( time.getFullYear() )
item.find('.js-today').bind('click', (e) -> item.find('.js-today').bind('click', (e) ->
e.preventDefault() e.preventDefault()
@ -462,9 +463,10 @@ class App.ControllerForm extends App.Controller
number number
if !reset && (year isnt '' && month isnt '' && day isnt '' && hour isnt '' && day isnt '') if !reset && (year isnt '' && month isnt '' && day isnt '' && hour isnt '' && day isnt '')
time = new Date( Date.parse( "#{year}-#{format(month)}-#{format(day)}T#{format(hour)}:#{format(minute)}:00Z" ) ) time = new Date( Date.parse( "#{year}-#{format(month)}-#{format(day)}T#{format(hour)}:#{format(minute)}:00Z" ) )
time.setMinutes( time.getMinutes() + diff + time.getTimezoneOffset() )
else else
time = new Date() time = new Date()
time.setMinutes( time.getMinutes() + diff + time.getTimezoneOffset() ) time.setMinutes( time.getMinutes() + diff )
#console.log('T', time, time.getHours(), time.getMinutes()) #console.log('T', time, time.getHours(), time.getMinutes())
item.closest('.form-group').find("[name=\"{datetime}#{name}___day\"]").val( time.getDate() ) item.closest('.form-group').find("[name=\"{datetime}#{name}___day\"]").val( time.getDate() )
item.closest('.form-group').find("[name=\"{datetime}#{name}___month\"]").val( time.getMonth()+1 ) item.closest('.form-group').find("[name=\"{datetime}#{name}___month\"]").val( time.getMonth()+1 )

View file

@ -249,3 +249,83 @@ test( "date validation check", function() {
equal( el.find('[data-name="date1"]').closest('.form-group').find('.help-inline').text(), '', 'check date1 error message') equal( el.find('[data-name="date1"]').closest('.form-group').find('.help-inline').text(), '', 'check date1 error message')
}); });
test( "datetime selector check", function() {
$('#forms').append('<hr><h1>datetime selector check</h1><form id="form4"></form>')
var el = $('#form4')
var defaults = {}
var form = new App.ControllerForm({
el: el,
model: {
configure_attributes: [
{ name: 'datetime1', display: 'Datetime1', tag: 'datetime', null: false, default: defaults['datetime1'] },
],
},
params: defaults,
});
// check params
params = App.ControllerForm.params( el )
test_params = {
datetime1: undefined,
}
deepEqual( params, test_params, 'params check' )
el.find('.js-today').click()
// check params
timeStamp = new Date()
currentTime = timeStamp.toISOString()
currentTime = currentTime.replace(/(\d\d\.\d\d\dZ)$/, '00.000Z')
params = App.ControllerForm.params( el )
test_params = {
datetime1: currentTime,
}
deepEqual( params, test_params, 'params check' )
});
test( "date selector check", function() {
$('#forms').append('<hr><h1>date selector check</h1><form id="form5"></form>')
var el = $('#form5')
var defaults = {}
var form = new App.ControllerForm({
el: el,
model: {
configure_attributes: [
{ name: 'date1', display: 'Datet1', tag: 'date', null: false, default: defaults['date1'] },
],
},
params: defaults,
});
// check params
params = App.ControllerForm.params( el )
test_params = {
date1: undefined,
}
deepEqual( params, test_params, 'params check' )
el.find('.js-today').click()
// check params
format = function (number) {
if ( parseInt(number) < 10 ) {
number = '0' + number.toString()
}
return number
}
timeStamp = new Date()
currentTime = timeStamp.getFullYear() + '-' + format(timeStamp.getMonth()+1) + '-' + format(timeStamp.getDate())
params = App.ControllerForm.params( el )
test_params = {
date1: currentTime,
}
deepEqual( params, test_params, 'params check' )
});