tsync

package
v0.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 27, 2026 License: MIT Imports: 2 Imported by: 1

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

View Source
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
View Source
const FAT32Tolerance = 2 * time.Second

FAT32Tolerance is the tolerance for FAT32 filesystems (2-second precision).

View Source
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

func After(t1, t2 time.Time) bool

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

func AfterWithTolerance(t1, t2 time.Time, tolerance time.Duration) bool

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

func Before(t1, t2 time.Time) bool

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

func BeforeWithTolerance(t1, t2 time.Time, tolerance time.Duration) bool

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

func Compare(t1, t2 time.Time) int

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

func CompareWithTolerance(t1, t2 time.Time, tolerance time.Duration) int

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

func Equal(t1, t2 time.Time) bool

Equal compares two timestamps with the default tolerance. Returns true if the timestamps are within DefaultTolerance of each other.

func EqualWithTolerance

func EqualWithTolerance(t1, t2 time.Time, tolerance time.Duration) bool

EqualWithTolerance compares two timestamps with a custom tolerance. Returns true if the absolute difference is less than or equal to the tolerance.

func FromTimespec

func FromTimespec(ts syscall.Timespec) time.Time

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

func FromTimeval(tv syscall.Timeval) time.Time

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

func Newer(t1, t2 time.Time) time.Time

Newer returns the newer of two timestamps. If they're within tolerance, returns t1 (arbitrary but consistent choice).

func Older

func Older(t1, t2 time.Time) time.Time

Older returns the older of two timestamps. If they're within tolerance, returns t1 (arbitrary but consistent choice).

func Tolerance

func Tolerance() time.Duration

Tolerance returns the recommended tolerance for comparing file modification times. Use this when synchronizing files across different platforms or filesystems.

func Truncate

func Truncate(t time.Time, precision time.Duration) time.Time

Truncate truncates a timestamp to the given precision. This is useful for normalizing timestamps before comparison. Common precisions:

  • time.Second for FAT32 compatibility
  • time.Millisecond for network compatibility
  • 100*time.Nanosecond for NTFS native precision

func TruncateToSecond

func TruncateToSecond(t time.Time) time.Time

TruncateToSecond truncates a timestamp to second precision. This is the safest precision for cross-platform file synchronization.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL