Skip to content

Commit

Permalink
resolves asciidoctor#1372 set localyear and docyear attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
mojavelinux committed Jan 5, 2017
1 parent 8099fda commit e79df8c
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
1 change: 1 addition & 0 deletions lib/asciidoctor.rb
Expand Up @@ -1324,6 +1324,7 @@ def load input, options = {}
attributes['docname'] = Helpers.basename input_path, (attributes['docfilesuffix'] = ::File.extname input_path)
docdate = (attributes['docdate'] ||= input_mtime.strftime('%Y-%m-%d'))
doctime = (attributes['doctime'] ||= input_mtime.strftime('%H:%M:%S %Z'))
attributes['docyear'] ||= input_mtime.year
attributes['docdatetime'] = %(#{docdate} #{doctime})
elsif input.respond_to? :readlines
# NOTE tty, pipes & sockets can't be rewound, but can't be sniffed easily either
Expand Down
3 changes: 2 additions & 1 deletion lib/asciidoctor/document.rb
Expand Up @@ -404,6 +404,7 @@ def initialize data = nil, options = {}
# See https://reproducible-builds.org/specs/source-date-epoch/
now = ::ENV['SOURCE_DATE_EPOCH'] ? (::Time.at ::ENV['SOURCE_DATE_EPOCH'].to_i).utc : ::Time.now
localdate = (attrs['localdate'] ||= now.strftime('%Y-%m-%d'))
localyear = (attrs['localyear'] ||= now.year)
unless (localtime = attrs['localtime'])
begin
localtime = attrs['localtime'] = now.strftime('%H:%M:%S %Z')
Expand All @@ -415,7 +416,7 @@ def initialize data = nil, options = {}

# docdate, doctime and docdatetime should default to
# localdate, localtime and localdatetime if not otherwise set
attrs['docdate'] ||= localdate
attrs['docyear'] ||= localyear
attrs['doctime'] ||= localtime
attrs['docdatetime'] ||= %(#{localdate} #{localtime})

Expand Down

0 comments on commit e79df8c

Please sign in to comment.