Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion api/src/main/java/org/apache/cloudstack/api/BaseCmd.java
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public static enum HTTPMethod {
GET, POST, PUT, DELETE
}
public static enum CommandType {
BOOLEAN, DATE, FLOAT, DOUBLE, INTEGER, SHORT, LIST, LONG, OBJECT, MAP, STRING, TZDATE, UUID
BOOLEAN, DATE, FLOAT, DOUBLE, INTEGER, SHORT, LIST, LONG, OBJECT, MAP, STRING, UUID
}

private Object _responseObject;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class ListAsyncJobsCmd extends BaseListAccountResourcesCmd {
//////////////// API parameters /////////////////////
/////////////////////////////////////////////////////

@Parameter(name = ApiConstants.START_DATE, type = CommandType.TZDATE, description = "The start date of the async job (use format \"yyyy-MM-dd'T'HH:mm:ss'+'SSSS\")")
@Parameter(name = ApiConstants.START_DATE, type = CommandType.DATE, description = "The start date of the async job (use format \"yyyy-MM-dd'T'HH:mm:ss'+'SSSS\")")
private Date startDate;

/////////////////////////////////////////////////////
Expand Down
57 changes: 32 additions & 25 deletions server/src/main/java/com/cloud/api/dispatch/ParamProcessWorker.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,10 @@
public class ParamProcessWorker implements DispatchWorker {

private static final Logger s_logger = Logger.getLogger(ParamProcessWorker.class.getName());
public final DateFormat inputFormat = new SimpleDateFormat("yyyy-MM-dd");
public final DateFormat newInputFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
private static final String inputFormatString = "yyyy-MM-dd";
private static final String newInputFormatString = "yyyy-MM-dd HH:mm:ss";
public static final DateFormat inputFormat = new SimpleDateFormat(inputFormatString);
public static final DateFormat newInputFormat = new SimpleDateFormat(newInputFormatString);

@Inject
protected AccountManager _accountMgr;
Expand Down Expand Up @@ -333,26 +335,7 @@ private void setFieldValue(final Field field, final BaseCmd cmdObj, final Object
field.set(cmdObj, Boolean.valueOf(paramObj.toString()));
break;
case DATE:
// This piece of code is for maintaining backward compatibility
// and support both the date formats(Bug 9724)
final boolean isObjInNewDateFormat = isObjInNewDateFormat(paramObj.toString());
if (isObjInNewDateFormat) {
final DateFormat newFormat = newInputFormat;
synchronized (newFormat) {
field.set(cmdObj, newFormat.parse(paramObj.toString()));
}
} else {
final DateFormat format = inputFormat;
synchronized (format) {
Date date = format.parse(paramObj.toString());
if (field.getName().equals("startDate")) {
date = messageDate(date, 0, 0, 0);
} else if (field.getName().equals("endDate")) {
date = messageDate(date, 23, 59, 59);
}
field.set(cmdObj, date);
}
}
parseAndSetDate(field, cmdObj, paramObj);
break;
case FLOAT:
// Assuming that the parameters have been checked for required before now,
Expand Down Expand Up @@ -428,9 +411,6 @@ private void setFieldValue(final Field field, final BaseCmd cmdObj, final Object
}
}
break;
case TZDATE:
field.set(cmdObj, DateUtil.parseTZDateString(paramObj.toString()));
break;
case MAP:
default:
field.set(cmdObj, paramObj);
Expand All @@ -442,6 +422,33 @@ private void setFieldValue(final Field field, final BaseCmd cmdObj, final Object
" is not accessible]");
}
}
private void parseAndSetDate(Field field, BaseCmd cmdObj, Object paramObj) throws IllegalAccessException, ParseException {
try {
field.set(cmdObj, DateUtil.parseTZDateString(paramObj.toString()));
return;
} catch (ParseException parseException) {
s_logger.debug(String.format("Could not parse date [%s] with timezone parser, trying to parse without timezone.", paramObj));
}
if (isObjInNewDateFormat(paramObj.toString())) {
s_logger.debug(String.format("Parsing date [%s] using the [%s] format.", paramObj, newInputFormatString));
final DateFormat newFormat = newInputFormat;
synchronized (newFormat) {
field.set(cmdObj, newFormat.parse(paramObj.toString()));
}
} else {
s_logger.debug(String.format("Parsing date [%s] using the [%s] format.", paramObj, inputFormatString));
final DateFormat format = inputFormat;
synchronized (format) {
Date date = format.parse(paramObj.toString());
if (field.getName().equals("startDate")) {
date = messageDate(date, 0, 0, 0);
} else if (field.getName().equals("endDate")) {
date = messageDate(date, 23, 59, 59);
}
field.set(cmdObj, date);
}
}
}

private boolean isObjInNewDateFormat(final String string) {
final Matcher matcher = BaseCmd.newInputDateFormat.matcher(string);
Expand Down
41 changes: 3 additions & 38 deletions ui/src/components/view/StatsTab.vue
Original file line number Diff line number Diff line change
Expand Up @@ -289,26 +289,12 @@ export default {
mounted () {
this.fetchData()
},
computed: {
usebrowsertimezone: function () {
return this.$store.getters.usebrowsertimezone
}
},
watch: {
resource: function (newItem) {
if (!newItem || !newItem.id) {
return
}
this.fetchData()
},
usebrowsertimezone: function () {
if (this.startDate) {
this.startDate = this.onToggleUseBrowserTimezone(new Date(this.startDate))
}
if (this.endDate) {
this.endDate = this.onToggleUseBrowserTimezone(new Date(this.endDate))
}
this.fetchData()
}
},
methods: {
Expand Down Expand Up @@ -355,43 +341,22 @@ export default {
},
getStartDate () {
var now = new Date()
if (!this.$store.getters.usebrowsertimezone) {
var dateInUTC = new Date(now.getTime() + now.getTimezoneOffset() * 60000)
return dateInUTC.setHours(dateInUTC.getHours() - 1)
}
now.setHours(now.getHours() - 1)
return now
},
getEndDate () {
var now = new Date()
if (this.$store.getters.usebrowsertimezone) {
return now
}
return new Date(now.getTime() + now.getTimezoneOffset() * 60000)
},
onToggleUseBrowserTimezone (date) {
if (this.$store.getters.usebrowsertimezone) {
return this.$toLocalDate(date)
}
return new Date(date.getTime() + date.getTimezoneOffset() * 60000)
},
convertAndFormatDateAppropriately (date) {
if (this.$store.getters.usebrowsertimezone) {
var dateInUTC = new Date(date).toISOString().split('T')
return dateInUTC[0] + ' ' + dateInUTC[1].split('-')[0].split('.')[0]
}
return moment(date).format('YYYY-MM-DD HH:mm:ss')
return new Date()
},
fetchData () {
this.loaded = false
this.showResourceInfoModal = false
this.formatPeriod()
var params = { id: this.resource.id }
if (this.startDate) {
params.startDate = this.convertAndFormatDateAppropriately(this.startDate)
params.startDate = moment(this.startDate).format()
}
if (this.endDate) {
params.endDate = this.convertAndFormatDateAppropriately(this.endDate)
params.endDate = moment(this.endDate).format()
}
api('listVirtualMachinesUsageHistory', params).then(response => {
this.handleStatsResponse(response)
Expand Down