times

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jan 24, 2016 License: MIT Imports: 3 Imported by: 0

README

times

GoDoc Release Software License Build Status Coverage Status

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

Documentation

Overview

Package times provides a platform-independent way to get atime, mtime, ctime and btime for files.

Index

Constants

View Source
const (
	HasChangeTime = true
	HasBirthTime  = false
)

HasChangeTime and HasBirthTime are true if and only if the target OS supports them.

Variables

This section is empty.

Functions

This section is empty.

Types

type Timespec

type Timespec interface {
	ModTime() time.Time
	AccessTime() time.Time
	ChangeTime() time.Time
	BirthTime() time.Time
	HasChangeTime() bool
	HasBirthTime() bool
}

Timespec provides access to file times. ChangeTime() panics unless HasChangeTime() is true and BirthTime() panics unless HasBirthTime() is true.

func Get

func Get(fi os.FileInfo) Timespec

Get returns the Timespec for the given FileInfo

func Stat

func Stat(name string) (Timespec, error)

Stat returns the Timespec for the given filename.

Jump to

Keyboard shortcuts

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