Skip to content

Commit ace687e

Browse files
[DOC] Doc for file-system timestamps (ruby#16722)
1 parent 4f26d80 commit ace687e

2 files changed

Lines changed: 85 additions & 0 deletions

File tree

doc/.document

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,5 @@ jit
1010
security
1111
language
1212
strscan
13+
file
14+

doc/file/timestamps.md

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
# \File System Timestamps
2+
3+
A file system entry (the name of a file or directory)
4+
has several times (called timestamps) associated with it.
5+
6+
The Ruby methods that return these timestamps (each as a Time object)
7+
are actually returning "whatever the OS says,"
8+
and so their behaviors may vary among OS platforms.
9+
If a platform does not support a particular timestamp,
10+
the corresponding Ruby methods raise NotImplementedError.
11+
12+
These timestamps are:
13+
14+
| Name | Meaning | Changes |
15+
|:--------------------------------:|----------------------------------------|-----------------------|
16+
| [`birthtime`](#birth-time) | Create time. | Never. |
17+
| [`mtime`](#modification-time) | Modification time. | When written. |
18+
| [`atime`](#access-time) | Access time. | When read or written. |
19+
| [`ctime`](#metadata-change-time) | Metadata-change time (or create time). | See below. |
20+
21+
## Birth \Time
22+
23+
The birth time for an entry is the time the entry was created.
24+
The birth time does not change, although if the entry is deleted and re-created,
25+
the birth time will be different.
26+
27+
Each of these methods returns the birth time for an entry as a Time object:
28+
29+
- File::birthtime.
30+
- File#birthtime.
31+
- File::Stat#birthtime.
32+
- Pathname#birthtime.
33+
34+
On Windows, each of these methods also returns the birth time:
35+
36+
- File::ctime.
37+
- File#ctime.
38+
- File::Stat#ctime.
39+
- Pathname#ctime.
40+
41+
## Modification \Time
42+
43+
The modification time for an entry is the time the entry was last modified.
44+
The modification time is updated when the entry is written,
45+
though some file systems may delay the update.
46+
47+
Each of these methods returns the modification time for an entry as a Time object:
48+
49+
- File::mtime.
50+
- File#mtime.
51+
- File::Stat#mtime.
52+
- Pathname#mtime.
53+
54+
## Access \Time
55+
56+
The access time for an entry is the time the entry last read.
57+
The access time is updated when the entry is read,
58+
though some file systems may delay the update.
59+
60+
Each of these methods returns the access time for an entry as a Time object:
61+
62+
- File::atime.
63+
- File#atime.
64+
- File::Stat#atime.
65+
- Pathname#atime.
66+
67+
## Metadata-Change \Time
68+
69+
The metadata-change time for an entry is the time the entry last read.
70+
The metadata-change time is updated when the entry's metadata is changed;
71+
changing access mode or permissions may update the metadata-change time,
72+
though some file systems may delay the update.
73+
74+
On non-Windows systems,
75+
each of these methods returns the metadata-change time for an entry:
76+
77+
- File::ctime.
78+
- File#ctime.
79+
- File::Stat#ctime.
80+
- Pathname#ctime.
81+
82+
On Windows, each `ctime` method returns the birth time,
83+
not the metadata-change time.

0 commit comments

Comments
 (0)