2021-03-10 16:47:44 +08:00
|
|
|
function ccn_datetimepicker_Insert() {
|
|
|
|
|
$('body').append(ccn_template_datetimepicker.render());
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-08 16:22:04 +08:00
|
|
|
function ccn_datetimepicker_Init() {
|
|
|
|
|
var nowtime = new Date();
|
|
|
|
|
|
|
|
|
|
$('.datetimepicker-year').attr('min', ccn_datetime_MIN_YEAR)
|
|
|
|
|
.attr('max', ccn_datetime_MAX_YEAR)
|
|
|
|
|
.attr('step', 1)
|
|
|
|
|
.val(nowtime.getFullYear())
|
2021-02-08 22:30:01 +08:00
|
|
|
.bind('input propertychange', ccn_datetimepicker_Sync);
|
2021-02-08 16:22:04 +08:00
|
|
|
|
|
|
|
|
$('.datetimepicker-month').attr('min', 1)
|
|
|
|
|
.attr('max', 12)
|
|
|
|
|
.attr('step', 1)
|
|
|
|
|
.val(nowtime.getMonth() + 1)
|
2021-02-08 22:30:01 +08:00
|
|
|
.bind('input propertychange', ccn_datetimepicker_Sync);
|
2021-02-08 16:22:04 +08:00
|
|
|
|
|
|
|
|
$('.datetimepicker-day').attr('min', 1)
|
|
|
|
|
.attr('step', 1)
|
|
|
|
|
.each(function(){
|
|
|
|
|
ccn_datetimepicker_SyncEx($(this).attr("datetimepicker"));
|
|
|
|
|
})
|
|
|
|
|
.val(nowtime.getDate());
|
|
|
|
|
|
|
|
|
|
$('.datetimepicker-hour').attr('min', 0)
|
|
|
|
|
.attr('max', 23)
|
|
|
|
|
.attr('step', 1)
|
|
|
|
|
.val(nowtime.getHours());
|
|
|
|
|
|
|
|
|
|
$('.datetimepicker-minute').attr('min', 0)
|
|
|
|
|
.attr('max', 59)
|
|
|
|
|
.attr('step', 1)
|
|
|
|
|
.val(nowtime.getMinutes());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function ccn_datetimepicker_Sync() {
|
|
|
|
|
var pickerIndex = $(this).attr("datetimepicker");
|
|
|
|
|
ccn_datetimepicker_SyncEx(pickerIndex);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function ccn_datetimepicker_SyncEx(pickerIndex) {
|
2021-02-08 22:30:01 +08:00
|
|
|
year = parseInt($('.datetimepicker-year[datetimepicker=' + pickerIndex + ']').val());
|
|
|
|
|
month = parseInt($('.datetimepicker-month[datetimepicker=' + pickerIndex + ']').val());
|
2021-02-08 16:22:04 +08:00
|
|
|
|
|
|
|
|
dayDOM = $('.datetimepicker-day[datetimepicker=' + pickerIndex + ']');
|
|
|
|
|
if (typeof(year) == 'undefined' || typeof(month) == 'undefined') {
|
|
|
|
|
dayDOM.attr('max', 1)
|
|
|
|
|
.val(1);
|
|
|
|
|
} else {
|
|
|
|
|
dayDOM.attr('max', ccn_datetime_monthDayCount[month - 1] + ((month == 2 && ccn_datetime_IsLeapYear(year) ? 1 : 0)))
|
|
|
|
|
.val(1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-09 17:10:05 +08:00
|
|
|
function ccn_datetimepicker_Set(pickerIndex, dt, isUTC) {
|
|
|
|
|
$('.datetimepicker-year[datetimepicker=' + pickerIndex + ']').val(isUTC ? dt.getUTCFullYear() : dt.getFullYear());
|
|
|
|
|
$('.datetimepicker-month[datetimepicker=' + pickerIndex + ']').val((isUTC ? dt.getUTCMonth() : dt.getMonth()) + 1);
|
|
|
|
|
$('.datetimepicker-day[datetimepicker=' + pickerIndex + ']').val(isUTC ? dt.getUTCDate() : dt.getDate());
|
|
|
|
|
$('.datetimepicker-hour[datetimepicker=' + pickerIndex + ']').val(isUTC ? dt.getUTCHours() : dt.getHours());
|
|
|
|
|
$('.datetimepicker-minute[datetimepicker=' + pickerIndex + ']').val(isUTC ? dt.getUTCMinutes() : dt.getMinutes());
|
2021-02-08 16:22:04 +08:00
|
|
|
}
|
|
|
|
|
|
2021-02-09 17:10:05 +08:00
|
|
|
function ccn_datetimepicker_Get(pickerIndex, isUTC) {
|
2021-02-08 16:22:04 +08:00
|
|
|
year = $('.datetimepicker-year[datetimepicker=' + pickerIndex + ']').val();
|
|
|
|
|
month = $('.datetimepicker-month[datetimepicker=' + pickerIndex + ']').val();
|
|
|
|
|
day = $('.datetimepicker-day[datetimepicker=' + pickerIndex + ']').val();
|
|
|
|
|
hour = $('.datetimepicker-hour[datetimepicker=' + pickerIndex + ']').val();
|
|
|
|
|
minute = $('.datetimepicker-minute[datetimepicker=' + pickerIndex + ']').val();
|
|
|
|
|
if (IsUndefinedOrEmpty(year)) year = ccn_datetime_MIN_YEAR;
|
|
|
|
|
if (IsUndefinedOrEmpty(month)) month = 1;
|
|
|
|
|
if (IsUndefinedOrEmpty(day)) day = 1;
|
|
|
|
|
if (IsUndefinedOrEmpty(hour)) hour = 0;
|
|
|
|
|
if (IsUndefinedOrEmpty(minute)) minute = 0;
|
|
|
|
|
|
2021-02-09 17:10:05 +08:00
|
|
|
if (isUTC) return new Date(Date.UTC(year, parseInt(month) - 1, day, hour, minute, 0, 0));
|
|
|
|
|
else return new Date(year, parseInt(month) - 1, day, hour, minute, 0, 0);
|
2021-02-08 16:22:04 +08:00
|
|
|
}
|