Add constructor for Date and DateTime
It is needed to be able to differentiate Date and DateTime because Javascript as only a datetime object named Date. review1115003
This commit is contained in:
1 parent
cbd80ce5fd
commit
d10b366a27
6 files changed
+55
-26
No files matched your search
+2
-1
@@ -105,7 +105,8 @@
|
||||
};
|
||||
|
||||
Sao.common.parse_datetime = function(date_format, time_format, value) {
|
||||
var date = jQuery.datepicker.parseDate(date_format, value);
|
||||
var date = Sao.DateTime(
|
||||
jQuery.datepicker.parseDate(date_format, value));
|
||||
var time_value = value.replace(jQuery.datepicker.formatDate(
|
||||
date_format + ' ', date), '');
|
||||
var time = Sao.common.parse_time(time_format, time_value);
|
||||
|
||||
+2
-2
@@ -1153,8 +1153,8 @@
|
||||
set_client: function(record, value, force_change) {
|
||||
if (!(value instanceof Date)) {
|
||||
try {
|
||||
value = jQuery.datepicker.parseDate(
|
||||
Sao.common.date_format(), value);
|
||||
value = Sao.Date(jQuery.datepicker.parseDate(
|
||||
Sao.common.date_format(), value));
|
||||
} catch (e) {
|
||||
value = this._default;
|
||||
}
|
||||
|
||||
+8
-9
@@ -26,8 +26,12 @@
|
||||
if (v instanceof Sao.PYSON.PYSON) {
|
||||
return v.pyson();
|
||||
} else if (v instanceof Date) {
|
||||
if (v.getHours() || v.getMinutes() || v.getSeconds() ||
|
||||
v.getMilliseconds()) {
|
||||
if (v.isDate) {
|
||||
return Sao.PYSON.Date(
|
||||
v.getFullYear(),
|
||||
v.getMonth(),
|
||||
v.getDate()).pyson();
|
||||
} else {
|
||||
return Sao.PYSON.DateTime(
|
||||
v.getFullYear(),
|
||||
v.getMonth(),
|
||||
@@ -36,11 +40,6 @@
|
||||
v.getMinutes(),
|
||||
v.getSeconds(),
|
||||
v.getMilliseconds()).pyson();
|
||||
} else {
|
||||
return Sao.PYSON.DateTime(
|
||||
v.getFullYear(),
|
||||
v.getMonth(),
|
||||
v.getDate()).pyson();
|
||||
}
|
||||
}
|
||||
return v;
|
||||
@@ -544,7 +543,7 @@
|
||||
});
|
||||
|
||||
Sao.PYSON.Date.eval_ = function(value, context) {
|
||||
var date = new Date();
|
||||
var date = Sao.Date();
|
||||
date.setHours(0);
|
||||
date.setMinutes(0);
|
||||
date.setSeconds(0);
|
||||
@@ -610,7 +609,7 @@
|
||||
});
|
||||
|
||||
Sao.PYSON.DateTime.eval_ = function(value, context) {
|
||||
var date = new Date();
|
||||
var date = Sao.DateTime();
|
||||
if (value.y) date.setFullYear(value.y);
|
||||
if (value.M) date.setMonth(value.M - 1);
|
||||
if (value.d) date.setDate(value.d);
|
||||
|
||||
+10
-12
@@ -68,12 +68,12 @@
|
||||
if (value && value.__class__) {
|
||||
switch (value.__class__) {
|
||||
case 'datetime':
|
||||
value = new Date(Date.UTC(value.year,
|
||||
value = Sao.DateTime(Date.UTC(value.year,
|
||||
value.month - 1, value.day, value.hour,
|
||||
value.minute, value.second));
|
||||
break;
|
||||
case 'date':
|
||||
value = new Date(value.year,
|
||||
value = Sao.Date(value.year,
|
||||
value.month - 1, value.day);
|
||||
break;
|
||||
case 'time':
|
||||
@@ -117,9 +117,14 @@
|
||||
} else if ((typeof(value) != 'string') &&
|
||||
(typeof(value) != 'number') && (value !== null)) {
|
||||
if (value instanceof Date) {
|
||||
if (value.getHours() || value.getMinutes() ||
|
||||
value.getSeconds())
|
||||
{
|
||||
if (value.isDate){
|
||||
value = {
|
||||
'__class__': 'date',
|
||||
'year': value.getFullYear(),
|
||||
'month': value.getMonth() + 1,
|
||||
'day': value.getDate()
|
||||
};
|
||||
} else {
|
||||
value = {
|
||||
'__class__': 'datetime',
|
||||
'year': value.getUTCFullYear(),
|
||||
@@ -129,13 +134,6 @@
|
||||
'minute': value.getUTCMinutes(),
|
||||
'second': value.getUTCSeconds()
|
||||
};
|
||||
} else {
|
||||
value = {
|
||||
'__class__': 'date',
|
||||
'year': value.getFullYear(),
|
||||
'month': value.getMonth() + 1,
|
||||
'day': value.getDate()
|
||||
};
|
||||
}
|
||||
if (parent) {
|
||||
parent[index] = value;
|
||||
|
||||
+31
@@ -35,6 +35,37 @@ var Sao = {};
|
||||
|
||||
Sao.Decimal = Number;
|
||||
|
||||
Sao.Date = function(year, month, day) {
|
||||
var date;
|
||||
if (year === undefined) {
|
||||
date = new Date();
|
||||
} else if (date === undefined) {
|
||||
date = new Date(year);
|
||||
} else {
|
||||
date = new Date(year, month, day);
|
||||
}
|
||||
date.isDate = true;
|
||||
date.setHours(0);
|
||||
date.setMinutes(0);
|
||||
date.setSeconds(0);
|
||||
date.setMilliseconds(0);
|
||||
return date;
|
||||
};
|
||||
|
||||
Sao.DateTime = function(year, month, day, hour, minute, second) {
|
||||
var datetime;
|
||||
if (year === undefined) {
|
||||
datetime = new Date();
|
||||
} else if (month === undefined) {
|
||||
datetime = new Date(year);
|
||||
} else {
|
||||
datetime = new Date(year, month, day, hour, minute, second);
|
||||
}
|
||||
datetime.isDateTime = true;
|
||||
datetime.setMilliseconds(0);
|
||||
return datetime;
|
||||
};
|
||||
|
||||
Sao.Time = Sao.class_(Object, {
|
||||
init: function(hour, minute, second) {
|
||||
this.date = new Date(0, 0, 0, hour, minute, second);
|
||||
|
||||
+2
-2
@@ -18,8 +18,8 @@
|
||||
'foo': true,
|
||||
'bar': false
|
||||
},
|
||||
'datetime': new Date(2012, 11, 29, 19, 59, 10),
|
||||
'date': new Date(2012, 11, 29),
|
||||
'datetime': Sao.DateTime(2012, 11, 29, 19, 59, 10),
|
||||
'date': Sao.Date(2012, 11, 29),
|
||||
'decimal': new Sao.Decimal(1.1),
|
||||
'null': null
|
||||
};
|
||||
|
||||
Reference in new issue
Block a user