Commit
…ndar for Java 1.8+
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,7 +24,8 @@ | |
import java.io.IOException; | ||
import java.io.OutputStream; | ||
import java.text.SimpleDateFormat; | ||
import java.util.Calendar; | ||
import java.time.ZonedDateTime; | ||
import java.time.temporal.ChronoUnit; | ||
import java.util.Date; | ||
import java.util.Locale; | ||
import java.util.TimeZone; | ||
|
@@ -53,7 +54,7 @@ public class RolloverFileOutputStream extends FilterOutputStream | |
final static int ROLLOVER_FILE_RETAIN_DAYS = 31; | ||
|
||
private RollTask _rollTask; | ||
private Calendar midnight; | ||
private ZonedDateTime midnight; | ||
private SimpleDateFormat _fileBackupFormat; | ||
private SimpleDateFormat _fileDateFormat; | ||
|
||
|
@@ -175,13 +176,7 @@ public RolloverFileOutputStream(String filename, | |
|
||
_rollTask=new RollTask(); | ||
|
||
midnight = Calendar.getInstance(); | ||
midnight.setTimeZone(zone); | ||
// set to midnight | ||
midnight.set(Calendar.HOUR, 0); | ||
midnight.set(Calendar.MINUTE, 0); | ||
midnight.set(Calendar.SECOND, 0); | ||
midnight.set(Calendar.MILLISECOND, 0); | ||
midnight = ZonedDateTime.now().toLocalDate().atStartOfDay(zone.toZoneId()); | ||
|
||
scheduleNextRollover(); | ||
} | ||
|
@@ -193,8 +188,8 @@ private void scheduleNextRollover() | |
// Using Calendar.add(DAY, 1) takes in account Daylights Savings | ||
// differences, and still maintains the "midnight" settings for | ||
// Hour, Minute, Second, Milliseconds | ||
midnight.add(Calendar.DAY_OF_MONTH, 1); | ||
__rollover.schedule(_rollTask,midnight.getTime()); | ||
midnight = midnight.toLocalDate().plus(1, ChronoUnit.DAYS).atStartOfDay(midnight.getZone()); | ||
__rollover.schedule(_rollTask,midnight.toInstant().toEpochMilli()); | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
joakime
Author
Contributor
|
||
} | ||
|
||
/* ------------------------------------------------------------ */ | ||
|
@@ -265,9 +260,9 @@ private void removeOldFiles() | |
{ | ||
if (_retainDays>0) | ||
{ | ||
Calendar now = Calendar.getInstance(); | ||
now.add(Calendar.DAY_OF_MONTH, (-1)*_retainDays); | ||
long expired = now.getTimeInMillis(); | ||
ZonedDateTime now = ZonedDateTime.now(this.midnight.getZone()); | ||
now.minus(_retainDays, ChronoUnit.DAYS); | ||
long expired = now.toInstant().toEpochMilli(); | ||
|
||
File file= new File(_filename); | ||
File dir = new File(file.getParent()); | ||
|
Hi, it seems that using schedule() with Date as it previously was is not the same as using with long as is now, as the long parameter is a delay:
https://docs.oracle.com/javase/7/docs/api/java/util/Timer.html#schedule(java.util.TimerTask,%20java.util.Date)
vs
https://docs.oracle.com/javase/7/docs/api/java/util/Timer.html#schedule(java.util.TimerTask,%20long)
This results in no rollout performed the next midnight.
¿Would it make sense to wrap the second argument with new Date(..)?