Skip to content
This repository has been archived by the owner on Jan 15, 2019. It is now read-only.

Commit

Permalink
Merge pull request #1 from b0e/master
Browse files Browse the repository at this point in the history
[DateHelper] added getCurrentMonth and getNow
  • Loading branch information
chrnie committed Aug 1, 2017
2 parents cbcac41 + 839bebd commit 77ed52c
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions java/org/icinga/reporting/DateHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
* Class helping jasper to generate reports for the following periods
* - last week
* - last month
* - current month
* - last quarter
* - last year
*
Expand All @@ -28,8 +29,30 @@ public static void main(String[] args) {
System.out.println("Last-Quarter End: " + getLastQuarterEnd());
System.out.println("Last-Year Start: " + getLastYearStart());
System.out.println("Last-Year End: " + getLastYearEnd());
System.out.println("Current-Month Start: " + getCurrentMonthStart());
System.out.println("Now: " + getNow());
}

static public Timestamp getCurrentMonthStart() {
Calendar cal = Calendar.getInstance();
cal.setTime(new Date());
cal.set(Calendar.DAY_OF_MONTH, 1);
cal.set(Calendar.HOUR_OF_DAY, 0);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MILLISECOND, 0);
Timestamp ts = new Timestamp(cal.getTime().getTime());
return ts;
}

static public Timestamp getNow() {
Calendar cal = Calendar.getInstance();
cal.setTime(new Date());
Timestamp ts = new Timestamp(cal.getTime().getTime());
return ts;
}


static public Timestamp getLastWeekStart() {
Calendar cal = Calendar.getInstance();
cal.setTime(new Date());
Expand Down

0 comments on commit 77ed52c

Please sign in to comment.