Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/djherbis/times
#golang file times (atime, mtime, ctime, btime)
https://github.com/djherbis/times
Last synced: 4 months ago
JSON representation
#golang file times (atime, mtime, ctime, btime)
- Host: GitHub
- URL: https://github.com/djherbis/times
- Owner: djherbis
- License: mit
- Created: 2015-08-29T07:08:15.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2023-10-20T15:09:49.000Z (over 1 year ago)
- Last Synced: 2024-10-28T08:14:53.509Z (4 months ago)
- Language: Go
- Size: 106 KB
- Stars: 251
- Watchers: 7
- Forks: 30
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
times
==========[](https://godoc.org/github.com/djherbis/times)
[](https://github.com/djherbis/times/releases/latest)
[](LICENSE.txt)
[](https://github.com/djherbis/times/actions/workflows/go-test.yml)
[](https://coveralls.io/r/djherbis/times?branch=master)
[](https://goreportcard.com/report/github.com/djherbis/times)
[](https://sourcegraph.com/github.com/djherbis/times?badge)Usage
------------
File Times for #golangGo has a hidden time functions for most platforms, this repo makes them accessible.
```go
package mainimport (
"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 | js | aix |
|:-----:|:-------:|:-----:|:-------:|:---------:|:------:|:-------:|:----:|:------:|:-------:|:-----:|:-----:|:-----:|
| atime | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| mtime | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| ctime | ✓* | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | | ✓ | ✓ |
| btime | ✓ | ✓* | | | | ✓ | ✓| ✓ | | |* Linux btime requires kernel 4.11 and filesystem support, so HasBirthTime = false.
Use Timespec.HasBirthTime() to check if file has birth time.
Get(FileInfo) never returns 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 WindowsInstallation
------------
```sh
go get -u github.com/djherbis/times
```