Change some inconsistent relative dates

This commit is contained in:
Nathan Gray 2016-03-21 23:50:21 +00:00
parent f0d2e72521
commit 6a2167f11b

View File

@ -1303,15 +1303,12 @@ var et2_date_range = (function(){ "use strict"; return et2_inputWidget.extend({
// Show description // Show description
this.select.set_value(_value); this.select.set_value(_value);
var now = new Date(); var tempDate = new Date();
now.setUTCMinutes(-now.getTimezoneOffset()); var today = new Date(tempDate.getFullYear(), tempDate.getMonth(), tempDate.getDate(),0,-tempDate.getTimezoneOffset(),0);
now.setUTCHours(0);
now.setUTCSeconds(0);
// Use strings to avoid references // Use strings to avoid references
this.from.set_value(now.toJSON()); this.from.set_value(today.toJSON());
this.to.set_value(now.toJSON()); this.to.set_value(today.toJSON());
var relative = null; var relative = null;
for(var index in et2_date_range.relative_dates) for(var index in et2_date_range.relative_dates)
@ -1325,7 +1322,7 @@ var et2_date_range = (function(){ "use strict"; return et2_inputWidget.extend({
if(relative) if(relative)
{ {
var dates = ["from","to"]; var dates = ["from","to"];
var value = now.toJSON(); var value = today.toJSON();
for(var i = 0; i < dates.length; i++) for(var i = 0; i < dates.length; i++)
{ {
var date = dates[i]; var date = dates[i];
@ -1353,13 +1350,16 @@ jQuery.extend(et2_date_range,
{ {
value: 'Today', value: 'Today',
label: 'Today', label: 'Today',
from: '', from: function(date) {return date;},
to: '+1d' to: function(date) {return date;}
}, },
{ {
label: 'Yesterday', label: 'Yesterday',
value: 'Yesterday', value: 'Yesterday',
from: '-1d', from: function(date) {
date.setUTCDate(date.getUTCDate() - 1);
return date;
},
to: '' to: ''
}, },
{ {
@ -1387,20 +1387,49 @@ jQuery.extend(et2_date_range,
{ {
label: 'This month', label: 'This month',
value: 'This month', value: 'This month',
from: '', from: function(date)
to: '+1m' {
date.setUTCDate(1);
return date;
},
to: function(date)
{
date.setUTCMonth(date.getUTCMonth()+1);
date.setUTCDate(0);
return date;
}
}, },
{ {
label: 'Last month', label: 'Last month',
value: 'Last month', value: 'Last month',
from: '-1m', from: function(date)
to: '' {
date.setUTCMonth(date.getUTCMonth() - 1);
date.setUTCDate(1);
return date;
},
to: function(date)
{
date.setUTCMonth(date.getUTCMonth()+1);
date.setUTCDate(0);
return date;
}
}, },
{ {
label: 'Last 3 months', label: 'Last 3 months',
value: 'Last 3 months', value: 'Last 3 months',
from: '-3m', from: function(date)
to: '' {
date.setUTCMonth(date.getUTCMonth() - 2);
date.setUTCDate(1);
return date;
},
to: function(date)
{
date.setUTCMonth(date.getUTCMonth()+3);
date.setUTCDate(0);
return date;
}
}, },
/* /*
'This quarter'=> array(0,0,0,0, 0,0,0,0), // Just a marker, needs special handling 'This quarter'=> array(0,0,0,0, 0,0,0,0), // Just a marker, needs special handling