java.lang.Object
kala.compress.utils.TimeUtils
Utility class for handling time-related types and conversions.
Understanding UNIX vs NTFS timestamps:
- A UNIX timestamp is a primitive long starting at the UNIX Epoch on January 1st, 1970 at Coordinated Universal Time (UTC)
- An NTFS timestamp is a file time is a 64-bit value that represents the number of 100-nanosecond intervals that have elapsed since 12:00 A.M. January 1, 1601 Coordinated Universal Time (UTC).
- Since:
- 1.23
-
Field Summary
FieldsModifier and TypeFieldDescription(package private) static final longThe amount of 100-nanosecond intervals in one millisecond.private static final longThe amount of 100-nanosecond intervals in one second.(package private) static final long -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivatePrivate constructor to prevent instantiation of this utility class. -
Method Summary
Modifier and TypeMethodDescriptionstatic FileTimedosTimeToFileTime(long dosTime) Converts DOS time to Java time (number of milliseconds since epoch).static booleanisUnixTime(long seconds) Tests whether a given number of seconds (since Epoch) can be safely represented in the standard UNIX time.static booleanisUnixTime(FileTime time) Tests whether a FileTime can be safely represented in the standard UNIX time.static FileTimentfsTimeToFileTime(long ntfsTime) Converts NTFS time (100-nanosecond units since 1 January 1601) to a FileTime.static longtoNtfsTime(long javaTime) Converts Java time (milliseconds since Epoch) to NTFS time.static longtoNtfsTime(FileTime fileTime) Converts aFileTimeto NTFS time (100-nanosecond units since 1 January 1601).static longtoUnixTime(FileTime fileTime) ConvertsFileTimeto standard UNIX time.static FileTimetruncateToHundredNanos(FileTime fileTime) Truncates a FileTime to 100-nanosecond precision.static FileTimeunixTimeToFileTime(long time) Converts standard UNIX time (in seconds, UTC/GMT) toFileTime.
-
Field Details
-
HUNDRED_NANOS_PER_MILLISECOND
static final long HUNDRED_NANOS_PER_MILLISECONDThe amount of 100-nanosecond intervals in one millisecond. -
HUNDRED_NANOS_PER_SECOND
private static final long HUNDRED_NANOS_PER_SECONDThe amount of 100-nanosecond intervals in one second. -
WINDOWS_EPOCH_OFFSET
static final long WINDOWS_EPOCH_OFFSETWindows File TimesA file time is a 64-bit value that represents the number of 100-nanosecond intervals that have elapsed since 12:00 A.M. January 1, 1601 Coordinated Universal Time (UTC). This is the offset of Windows time 0 to UNIX epoch in 100-nanosecond intervals.
- See Also:
-
-
Constructor Details
-
TimeUtils
private TimeUtils()Private constructor to prevent instantiation of this utility class.
-
-
Method Details
-
isUnixTime
Tests whether a FileTime can be safely represented in the standard UNIX time.TODO ? If the FileTime is null, this method always returns true.
- Parameters:
time- the FileTime to evaluate, can be null.- Returns:
- true if the time exceeds the minimum or maximum UNIX time, false otherwise.
-
isUnixTime
public static boolean isUnixTime(long seconds) Tests whether a given number of seconds (since Epoch) can be safely represented in the standard UNIX time.- Parameters:
seconds- the number of seconds (since Epoch) to evaluate.- Returns:
- true if the time can be represented in the standard UNIX time, false otherwise.
-
ntfsTimeToFileTime
Converts NTFS time (100-nanosecond units since 1 January 1601) to a FileTime.- Parameters:
ntfsTime- the NTFS time in 100-nanosecond units.- Returns:
- the FileTime.
-
toNtfsTime
Converts aFileTimeto NTFS time (100-nanosecond units since 1 January 1601).- Parameters:
fileTime- the FileTime.- Returns:
- the NTFS time in 100-nanosecond units.
-
toNtfsTime
public static long toNtfsTime(long javaTime) Converts Java time (milliseconds since Epoch) to NTFS time.- Parameters:
javaTime- the Java time.- Returns:
- the NTFS time.
-
toUnixTime
ConvertsFileTimeto standard UNIX time.- Parameters:
fileTime- the original FileTime.- Returns:
- the UNIX timestamp.
-
truncateToHundredNanos
Truncates a FileTime to 100-nanosecond precision.- Parameters:
fileTime- the FileTime to be truncated.- Returns:
- the truncated FileTime.
-
unixTimeToFileTime
Converts standard UNIX time (in seconds, UTC/GMT) toFileTime.- Parameters:
time- UNIX timestamp (in seconds, UTC/GMT).- Returns:
- the corresponding FileTime.
-
dosTimeToFileTime
Converts DOS time to Java time (number of milliseconds since epoch).- Parameters:
dosTime- time to convert- Returns:
- converted time
- Since:
- 1.27.1-0
-