Skip to content

Commit 7c83e1b

Browse files
committed
Merge pull request #1205 from shapeblue/master-9126
QUOTA: Ensuring that the dates displayed are as per user expectations When querying db we use start of next day to query quota usage for today, but while displaying it to user we still need to show it as todays date * pr/1205: QUOTA: Ensuring that the dates displayed are as per user expectations Signed-off-by: Remi Bergsma <[email protected]>
2 parents c1533a1 + 1e17c3e commit 7c83e1b

File tree

3 files changed

+12
-7
lines changed

3 files changed

+12
-7
lines changed

plugins/database/quota/src/org/apache/cloudstack/api/command/QuotaBalanceCmd.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,12 @@ public void setDomainId(Long domainId) {
8383
}
8484

8585
public Date getEndDate() {
86-
return endDate == null ? null : _responseBuilder.startOfNextDay(endDate == null ? null : new Date(endDate.getTime()));
86+
if (endDate == null){
87+
return null;
88+
}
89+
else{
90+
return _responseBuilder.startOfNextDay(new Date(endDate.getTime()));
91+
}
8792
}
8893

8994
public void setEndDate(Date endDate) {
@@ -113,10 +118,10 @@ public void execute() {
113118
List<QuotaBalanceVO> quotaUsage = _responseBuilder.getQuotaBalance(this);
114119

115120
QuotaBalanceResponse response;
116-
if (getEndDate() == null) {
121+
if (endDate == null) {
117122
response = _responseBuilder.createQuotaLastBalanceResponse(quotaUsage, getStartDate());
118123
} else {
119-
response = _responseBuilder.createQuotaBalanceResponse(quotaUsage, getStartDate(), endDate == null ? null : new Date(endDate.getTime()));
124+
response = _responseBuilder.createQuotaBalanceResponse(quotaUsage, getStartDate(), new Date(endDate.getTime()));
120125
}
121126
response.setResponseName(getCommandName());
122127
setResponseObject(response);

plugins/database/quota/src/org/apache/cloudstack/api/response/QuotaResponseBuilderImpl.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -233,9 +233,9 @@ public int compare(QuotaBalanceVO o1, QuotaBalanceVO o2) {
233233
// order is desc last item is the start item
234234
QuotaBalanceVO startItem = quotaBalance.get(quotaBalance.size() - 1);
235235
QuotaBalanceVO endItem = quotaBalance.get(0);
236-
resp.setStartDate(startItem.getUpdatedOn());
236+
resp.setStartDate(startDate);
237237
resp.setStartQuota(startItem.getCreditBalance());
238-
resp.setEndDate(endItem.getUpdatedOn());
238+
resp.setEndDate(endDate);
239239
if (s_logger.isDebugEnabled()) {
240240
s_logger.debug("createQuotaBalanceResponse: Start Entry=" + startItem);
241241
s_logger.debug("createQuotaBalanceResponse: End Entry=" + endItem);
@@ -489,7 +489,7 @@ public QuotaBalanceResponse createQuotaLastBalanceResponse(List<QuotaBalanceVO>
489489
lastCredits = lastCredits.add(entry.getCreditBalance());
490490
}
491491
resp.setStartQuota(lastCredits);
492-
resp.setStartDate(_quotaService.computeAdjustedTime(startDate));
492+
resp.setStartDate(startDate);
493493
resp.setCurrency(QuotaConfig.QuotaCurrencySymbol.value());
494494
resp.setObjectName("balance");
495495
return resp;

plugins/database/quota/src/org/apache/cloudstack/quota/QuotaServiceImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ public List<QuotaUsageVO> getQuotaUsage(Long accountId, String accountName, Long
243243
Date adjustedEndDate = computeAdjustedTime(endDate);
244244
Date adjustedStartDate = computeAdjustedTime(startDate);
245245
if (s_logger.isDebugEnabled()) {
246-
s_logger.debug("Getting quota records for account: " + accountId + ", domainId: " + domainId + ", between " + startDate + " and " + endDate);
246+
s_logger.debug("Getting quota records for account: " + accountId + ", domainId: " + domainId + ", between " + adjustedStartDate + " and " + adjustedEndDate);
247247
}
248248
return _quotaUsageDao.findQuotaUsage(accountId, domainId, usageType, adjustedStartDate, adjustedEndDate);
249249
}

0 commit comments

Comments
 (0)