Documentation
¶
Overview ¶
Package tsync provides cross-platform timestamp utilities for file synchronization.
This package addresses platform differences in filesystem timestamp precision:
- Windows NTFS: ~100 nanosecond precision, but often rounded to 2 seconds for some operations
- Linux ext4/XFS: nanosecond precision
- macOS APFS: nanosecond precision
- FAT32: 2-second precision
- Network drives: varies widely
When synchronizing files across platforms or filesystems, timestamps should be compared with appropriate tolerance to avoid false positives.
Index ¶
- Constants
- func After(t1, t2 time.Time) bool
- func AfterWithTolerance(t1, t2 time.Time, tolerance time.Duration) bool
- func Before(t1, t2 time.Time) bool
- func BeforeWithTolerance(t1, t2 time.Time, tolerance time.Duration) bool
- func Compare(t1, t2 time.Time) int
- func CompareWithTolerance(t1, t2 time.Time, tolerance time.Duration) int
- func Equal(t1, t2 time.Time) bool
- func EqualWithTolerance(t1, t2 time.Time, tolerance time.Duration) bool
- func FromTimespec(ts syscall.Timespec) time.Time
- func FromTimeval(tv syscall.Timeval) time.Time
- func Newer(t1, t2 time.Time) time.Time
- func Older(t1, t2 time.Time) time.Time
- func Tolerance() time.Duration
- func Truncate(t time.Time, precision time.Duration) time.Time
- func TruncateToSecond(t time.Time) time.Time
Constants ¶
const DefaultTolerance = time.Second
DefaultTolerance is the recommended tolerance for cross-platform file synchronization. 1 second handles:
- FAT32 filesystems (2-second precision)
- Network drives with reduced precision
- Cross-platform timestamp differences
- Clock skew between systems
const FAT32Tolerance = 2 * time.Second
FAT32Tolerance is the tolerance for FAT32 filesystems (2-second precision).
const HighPrecisionTolerance = 100 * time.Millisecond
HighPrecisionTolerance is for comparing timestamps on modern filesystems with high precision (NTFS, ext4, APFS).
Variables ¶
This section is empty.
Functions ¶
func After ¶
After returns true if t1 is after t2, accounting for the default tolerance. This is more reliable than t1.After(t2) when comparing across filesystems.
func AfterWithTolerance ¶
AfterWithTolerance returns true if t1 is definitively after t2, accounting for the specified tolerance. Returns false if the times are within tolerance of each other.
func Before ¶
Before returns true if t1 is before t2, accounting for the default tolerance. This is more reliable than t1.Before(t2) when comparing across filesystems.
func BeforeWithTolerance ¶
BeforeWithTolerance returns true if t1 is definitively before t2, accounting for the specified tolerance. Returns false if the times are within tolerance of each other.
func Compare ¶
Compare compares two timestamps with the default tolerance. Returns:
-1 if t1 is before t2 (beyond tolerance) 0 if t1 and t2 are equal (within tolerance) +1 if t1 is after t2 (beyond tolerance)
func CompareWithTolerance ¶
CompareWithTolerance compares two timestamps with a custom tolerance. Returns:
-1 if t1 is before t2 (beyond tolerance) 0 if t1 and t2 are equal (within tolerance) +1 if t1 is after t2 (beyond tolerance)
func Equal ¶
Equal compares two timestamps with the default tolerance. Returns true if the timestamps are within DefaultTolerance of each other.
func EqualWithTolerance ¶
EqualWithTolerance compares two timestamps with a custom tolerance. Returns true if the absolute difference is less than or equal to the tolerance.
func FromTimespec ¶
FromTimespec converts a syscall.Timespec to time.Time. This handles platform differences in the Timespec field types.
On Windows, this function still accepts Timespec but it's rarely used since Windows uses different time structures (FILETIME).
func FromTimeval ¶
FromTimeval converts a syscall.Timeval to time.Time. This handles platform differences in the Timeval field types.
Note: Timeval has microsecond precision (Usec field), so some precision is lost compared to nanosecond-precision time.Time.
func Newer ¶
Newer returns the newer of two timestamps. If they're within tolerance, returns t1 (arbitrary but consistent choice).
func Older ¶
Older returns the older of two timestamps. If they're within tolerance, returns t1 (arbitrary but consistent choice).
func Tolerance ¶
Tolerance returns the recommended tolerance for comparing file modification times. Use this when synchronizing files across different platforms or filesystems.
Types ¶
This section is empty.