#golang file times (atime, mtime, ctime, btime)
Go
Latest commit d25002f Feb 15, 2017 @djherbis add sourcegraph badge
Permalink
Failed to load latest commit information.
.travis.yml changing travis to only run on 1.7 Dec 8, 2016
LICENSE initial commit Aug 29, 2015
README.md add sourcegraph badge Feb 15, 2017
bench_test.go adding benchmarks Jan 5, 2016
ctime_windows.go windows ctime lookup uses syscall to obtain filehandle instead of os Dec 8, 2016
times.go use platform specific stat if available, fallback to generic stat Jan 12, 2016
times_darwin.go simplifying api to use const for ChangeTime and BirthTime support Aug 30, 2015
times_dragonfly.go simplifying api to use const for ChangeTime and BirthTime support Aug 30, 2015
times_freebsd.go simplifying api to use const for ChangeTime and BirthTime support Aug 30, 2015
times_linux.go simplifying api to use const for ChangeTime and BirthTime support Aug 30, 2015
times_nacl.go simplifying api to use const for ChangeTime and BirthTime support Aug 30, 2015
times_netbsd.go simplifying api to use const for ChangeTime and BirthTime support Aug 30, 2015
times_openbsd.go simplifying api to use const for ChangeTime and BirthTime support Aug 30, 2015
times_plan9.go simplifying api to use const for ChangeTime and BirthTime support Aug 30, 2015
times_solaris.go simplifying api to use const for ChangeTime and BirthTime support Aug 30, 2015
times_test.go not all times on all platforms support ms precision, allowing +/- 1s … Aug 7, 2016
times_windows.go improved windows Get() performance (x100) by not returning ChangeTime Jan 5, 2016
use_generic_stat.go fixed undefined platformSpecificStat for non-windows builds Jan 24, 2016
util_test.go modularized tests, testing times within a range Jan 5, 2016

README.md

times

GoDoc Release Software License Build Status Coverage Status Go Report Card Sourcegraph

Usage

File Times for #golang

Go has a hidden time functions for most platforms, this repo makes them accessible.

package main

import (
  "log"

  "github.com/djherbis/times"
)

func main() {
  t, err := times.Stat("myfile")
  if err != nil {
    log.Fatal(err.Error())
  }

  log.Println(t.AccessTime())
  log.Println(t.ModTime())

  if t.HasChangeTime() {
    log.Println(t.ChangeTime())
  }

  if t.HasBirthTime() {
    log.Println(t.BirthTime())
  }
}

Supported Times

windows linux solaris dragonfly nacl freebsd darwin netbsd openbsd plan9
atime
mtime
ctime ✓*
btime
  • Windows XP does not have ChangeTime so HasChangeTime = false, however Vista onward does have ChangeTime so Timespec.HasChangeTime() will only return false on those platforms when the syscall used to obtain them fails.
  • Also note, Get(FileInfo) will now only return values available in FileInfo.Sys(), this means Stat() is required to get ChangeTime on Windows

Installation

go get github.com/djherbis/times