Skip to content

Commit

Permalink
Add Instant to FileTime (#782)
Browse files Browse the repository at this point in the history
Co-authored-by: Daniel Heid <daniel.heid@stromnetz-hamburg.de>
  • Loading branch information
dheid and Daniel Heid committed Aug 14, 2023
1 parent 65a986d commit 63b7a8a
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/main/java/com/hierynomus/msdtyp/FileTime.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package com.hierynomus.msdtyp;

import java.time.Instant;
import java.util.Date;
import java.util.concurrent.TimeUnit;

Expand All @@ -29,6 +30,10 @@ public static FileTime fromDate(Date date) {
return new FileTime(date.getTime() * NANO100_TO_MILLI + WINDOWS_TO_UNIX_EPOCH);
}

public static FileTime fromInstant(Instant instant) {
return new FileTime(instant.toEpochMilli() * NANO100_TO_MILLI + WINDOWS_TO_UNIX_EPOCH);
}

public static FileTime now() {
return ofEpochMillis(System.currentTimeMillis());
}
Expand Down Expand Up @@ -58,6 +63,10 @@ public long toEpoch(TimeUnit unit) {
return unit.convert((windowsTimeStamp - WINDOWS_TO_UNIX_EPOCH) * NANO100_TO_NANO, TimeUnit.NANOSECONDS);
}

public Instant toInstant() {
return Instant.ofEpochMilli(toEpochMillis());
}

public Date toDate() {
return new Date(toEpochMillis());
}
Expand Down

0 comments on commit 63b7a8a

Please sign in to comment.