Skip to content

Commit 62baed2

Browse files
author
José Valim
committed
Default to universal times throughout File
1 parent 939b64c commit 62baed2

File tree

4 files changed

+8
-5
lines changed

4 files changed

+8
-5
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ and is using Erlang 17.1, remember to update to at least Erlang 17.3.
140140
* [Code] `:delegate_locals_to` failed to delegate to the chosen module in many situations and messed up stacktraces. This option has therefore been replaced by imports
141141
* [Code] Store the documentation line in the metadata returned by `Code.get_docs/2`
142142
* [Exception] Do not fail when calculating an exception message, even if the message is invalid
143-
* [File] Ensure `File.touch/2` and `File.touch!/2` work with universal time
143+
* [File] Ensure `File.touch/2` and `File.stat/2` receive and return universal times. Previously they would work with local times which are not monotonically increasing, which could present issues on scripts. If the times are being shown to the user, `time: :local` can be given as argument
144144
* [Float] Support complete scientific notation in `Float.parse/1`
145145
* [Kernel] Do not expand `in/2` argument in module body
146146
* [Kernel] Throw syntax error for undefind atom/alias syntax `:foo.Bar`

lib/elixir/lib/file.ex

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -260,13 +260,14 @@ defmodule File do
260260
261261
The values for `:time` can be:
262262
263+
* `:universal` - returns a `{date, time}` tuple in UTC (default)
263264
* `:local` - returns a `{date, time}` tuple using the machine time
264-
* `:universal` - returns a `{date, time}` tuple in UTC
265265
* `:posix` - returns the time as integer seconds since epoch
266266
267267
"""
268268
@spec stat(Path.t, stat_options) :: {:ok, File.Stat.t} | {:error, posix}
269269
def stat(path, opts \\ []) do
270+
opts = Keyword.put_new(opts, :time, :universal)
270271
case F.read_file_info(IO.chardata_to_string(path), opts) do
271272
{:ok, fileinfo} ->
272273
{:ok, File.Stat.from_record(fileinfo)}
@@ -304,13 +305,14 @@ defmodule File do
304305
305306
The values for `:time` can be:
306307
308+
* `:universal` - returns a `{date, time}` tuple in UTC (default)
307309
* `:local` - returns a `{date, time}` tuple using the machine time
308-
* `:universal` - returns a `{date, time}` tuple in UTC
309310
* `:posix` - returns the time as integer seconds since epoch
310311
311312
"""
312313
@spec lstat(Path.t, stat_options) :: {:ok, File.Stat.t} | {:error, posix}
313314
def lstat(path, opts \\ []) do
315+
opts = Keyword.put_new(opts, :time, :universal)
314316
case F.read_link_info(IO.chardata_to_string(path), opts) do
315317
{:ok, fileinfo} ->
316318
{:ok, File.Stat.from_record(fileinfo)}
@@ -339,6 +341,7 @@ defmodule File do
339341
"""
340342
@spec write_stat(Path.t, File.Stat.t, stat_options) :: :ok | {:error, posix}
341343
def write_stat(path, stat, opts \\ []) do
344+
opts = Keyword.put_new(opts, :time, :universal)
342345
F.write_file_info(IO.chardata_to_string(path), File.Stat.to_record(stat), opts)
343346
end
344347

lib/elixir/test/elixir/file_test.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1527,7 +1527,7 @@ defmodule FileTest do
15271527
refute File.exists?(fixture)
15281528
assert File.touch(fixture, time) == :ok
15291529
assert {:ok, ""} == File.read(fixture)
1530-
assert File.stat!(fixture, time: :universal).mtime == time
1530+
assert File.stat!(fixture).mtime == time
15311531
after
15321532
File.rm(fixture)
15331533
end

lib/mix/lib/mix/utils.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ defmodule Mix.Utils do
101101
def last_modified(path) do
102102
now = :calendar.universal_time
103103

104-
case File.stat(path, time: :universal) do
104+
case File.stat(path) do
105105
{:ok, %File.Stat{mtime: mtime}} when mtime > now ->
106106
Mix.shell.error("warning: mtime (modified time) for \"#{path}\" was set to the future, resetting to now")
107107
File.touch!(path, now)

0 commit comments

Comments
 (0)