Merge pull request #11659 from carlocab/time

formula: add a `time` method for use as the build time
This commit is contained in:
Carlo Cabrera 2021-07-07 05:02:16 -07:00 committed by GitHub
commit 7c2a8f64ab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1551,6 +1551,18 @@ class Formula
"@loader_path/../lib"
end
# Creates a new `Time` object for use in the formula as the build time.
#
# @see https://www.rubydoc.info/stdlib/time/Time Time
sig { returns(Time) }
def time
if ENV["SOURCE_DATE_EPOCH"].present?
Time.at(ENV["SOURCE_DATE_EPOCH"].to_i).utc
else
Time.now.utc
end
end
# an array of all core {Formula} names
# @private
def self.core_names