Skip to content

Commit 3e6992d

Browse files
luguosheng1314binmahone
authored andcommitted
KYLIN-2508,Trans the time to UTC time when set the range of building cube
Signed-off-by: Hongbin Ma <[email protected]>
1 parent 5155994 commit 3e6992d

File tree

1 file changed

+39
-38
lines changed

1 file changed

+39
-38
lines changed

webapp/app/js/directives/directives.js

+39-38
Original file line numberDiff line numberDiff line change
@@ -249,49 +249,50 @@ KylinApp.directive('kylinPagination', function ($parse, $q) {
249249
}
250250
};
251251
}).directive('dateTimepickerTimezone', function () {
252-
// this directive workaround to convert GMT0 timestamp to GMT date for datepicker
253-
return {
254-
restrict: 'A',
255-
priority: 1,
256-
require: 'ngModel',
257-
link: function (scope, element, attrs, ctrl) {
258-
ctrl.$formatters.push(function (value) {
259-
260-
//set null for 0
261-
if(value===0){
262-
return '';
263-
}
264-
265-
//return value;
266-
var newDate = new Date(value + (60000 * new Date().getTimezoneOffset()));
267-
268-
var year = newDate.getFullYear();
269-
var month = (newDate.getMonth()+1)<10?'0'+(newDate.getMonth()+1):(newDate.getMonth()+1);
270-
var date = newDate.getDate()<10?'0'+newDate.getDate():newDate.getDate();
252+
return {
253+
restrict: 'A',
254+
priority: 1,
255+
require: 'ngModel',
256+
link: function (scope, element, attrs, ctrl) {
257+
ctrl.$formatters.push(function (value) {
271258

272-
var hour = newDate.getHours()<10?'0'+newDate.getHours():newDate.getHours();
273-
var mins = newDate.getMinutes()<10?'0'+newDate.getMinutes():newDate.getMinutes();
274-
var seconds = newDate.getSeconds()<10?'0'+newDate.getSeconds():newDate.getSeconds();
259+
//set null for 0
260+
if(value===0){
261+
return '';
262+
}
275263

276-
var viewVal = year+"-"+month+"-"+date+" "+hour+":"+mins+":"+seconds;
277-
return viewVal;
278-
});
264+
//return value;
265+
var newDate = new Date(value);
266+
var year = newDate.getUTCFullYear();
267+
var month = (newDate.getUTCMonth()+1)<10?'0'+(newDate.getUTCMonth()+1):(newDate.getUTCMonth()+1);
268+
var date = newDate.getUTCDate()<10?'0'+newDate.getUTCDate():newDate.getUTCDate();
269+
var hour = newDate.getUTCHours()<10?'0'+newDate.getUTCHours():newDate.getUTCHours();
270+
var mins = newDate.getUTCMinutes()<10?'0'+newDate.getUTCMinutes():newDate.getUTCMinutes();
271+
var seconds = newDate.getUTCSeconds()<10?'0'+newDate.getUTCSeconds():newDate.getUTCSeconds();
272+
var viewVal = year+"-"+month+"-"+date+" "+hour+":"+mins+":"+seconds;
273+
return viewVal;
274+
});
279275

280-
ctrl.$parsers.push(function (value) {
281-
var date;
282-
if(/^\d{4}-\d{1,2}-\d{1,2}(\s+\d{1,2}:\d{1,2}:\d{1,2})?$/.test(value)) {
283-
date=new Date(value);
284-
if(!date||date&&!date.getTime()){
285-
return value;
276+
ctrl.$parsers.push(function (value) {
277+
var date;
278+
if(/^\d{4}-\d{1,2}-\d{1,2}(\s+\d{1,2}:\d{1,2}:\d{1,2})?$/.test(value)) {
279+
date=new Date(value);
280+
if(!date||date&&!date.getTime()){
281+
return value;
282+
}else{
283+
var dateSplit=value.replace(/^\s+|\s+$/,'').replace(/\s+/,'-').split(/[:-]/);
284+
var resultDate=[];
285+
for(var i=0;i<6;i++){
286+
resultDate[i]=dateSplit[i]||0;
287+
}
288+
return Date.UTC(resultDate[0],resultDate[1]-1,resultDate[2],resultDate[3],resultDate[4],resultDate[5]);
289+
}
286290
}else{
287-
return date.getTime()-(60000 * date.getTimezoneOffset());
291+
return value;
288292
}
289-
}else{
290-
return value;
291-
}
292-
});
293-
}
294-
};
293+
});
294+
}
295+
};
295296
}).directive("parametertree", function($compile) {
296297
return {
297298
restrict: "E",

0 commit comments

Comments
 (0)