winterhazel commented on code in PR #12518:
URL: https://github.com/apache/cloudstack/pull/12518#discussion_r2731510304
##########
utils/src/main/java/org/apache/cloudstack/utils/usage/UsageUtils.java:
##########
@@ -19,6 +19,50 @@
package org.apache.cloudstack.utils.usage;
+import com.cloud.utils.DateUtil;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+
+import java.util.Calendar;
+import java.util.Date;
+import java.util.TimeZone;
+
public class UsageUtils {
+ protected static Logger logger = LogManager.getLogger(UsageUtils.class);
+
public static final int USAGE_AGGREGATION_RANGE_MIN = 1;
+
+ public static Date getNextJobExecutionTime(TimeZone usageTimeZone, String
jobExecTimeConfig) {
+ return getJobExecutionTime(usageTimeZone, jobExecTimeConfig, true);
+ }
+
+ public static Date getPreviousJobExecutionTime(TimeZone usageTimeZone,
String jobExecTimeConfig) {
+ return getJobExecutionTime(usageTimeZone, jobExecTimeConfig, false);
+ }
+
+ protected static Date getJobExecutionTime(TimeZone usageTimeZone, String
jobExecTimeConfig, boolean next) {
+ String[] execTimeSegments = jobExecTimeConfig.split(":");
+ if (execTimeSegments.length != 2) {
+ logger.warn("Unable to parse configuration
'usage.stats.job.exec.time'.");
+ return null;
+ }
+ int hourOfDay = Integer.parseInt(execTimeSegments[0]);
+ int minutes = Integer.parseInt(execTimeSegments[1]);
+
+ Date currentDate = DateUtil.currentGMTTime();
+ Calendar jobExecTime = Calendar.getInstance(usageTimeZone);
+ jobExecTime.setTime(currentDate);
+ jobExecTime.set(Calendar.HOUR_OF_DAY, hourOfDay);
+ jobExecTime.set(Calendar.MINUTE, minutes);
+ jobExecTime.set(Calendar.SECOND, 0);
+ jobExecTime.set(Calendar.MILLISECOND, 0);
+
+ if (next && jobExecTime.getTime().before(currentDate)) {
+ jobExecTime.roll(Calendar.DAY_OF_YEAR, true);
+ } else if (!next && jobExecTime.getTime().after(currentDate)) {
+ jobExecTime.roll(Calendar.DAY_OF_YEAR, false);
Review Comment:
Applying it as copilot is right:
```
2025-12-31 23:50:07,588 INFO
[cloud.usage.UsageManagerImpl_EnhancerByCloudStack_6851ab59] (main:[]) (logid:)
Usage is configured to execute in time zone [Etc/UTC], at [00:00], each [1440]
minutes; the current time in that timezone is [2025-12-31T23:50:07+0000] and
the next job is scheduled to execute at [2025-01-01T00:00:00+0000]. During its
execution, Usage will aggregate stats according to the time zone [GMT] defined
in global setting [usage.aggregation.timezone].
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]