Search code examples
javachroniclechronicle-queue

Chronicle Queue: Convert cycle integer to timestamp and vice-versa


Is there a way to convert between a certain cycle in Chronicle Queue to a timestamp? I checked the 4.5 apidocs and didn't find anything.


Solution

  • The cycle number is the number of days (or hours) since epoch. If your epoch is 0 then the time stamp is

    Date date = new Date(TimeUnit.DAYS.toMillis(cycle)); 
    

    You can do the reverse with

    long cycle = TimeUnit.MILLIS(System.currentTimeMillis()).toDays()
    

    If you have an hourly cycle, you can replace days with hours above.

    Using built in functions you can do this for any roll cycle.

    int cycle = rollCycle.current(() -> time, epoch);