class Asciidoctor::Document
def fill_datetime_attributes attrs, input_mtime
Internal: Assign the local and document datetime attributes, which includes localdate, localyear, localtime,
def fill_datetime_attributes attrs, input_mtime # See https://reproducible-builds.org/specs/source-date-epoch/ now = (::ENV.key? 'SOURCE_DATE_EPOCH') ? (source_date_epoch = (::Time.at Integer ::ENV['SOURCE_DATE_EPOCH']).utc) : ::Time.now if (localdate = attrs['localdate']) attrs['localyear'] ||= (localdate.index '-') == 4 ? (localdate.slice 0, 4) : nil else localdate = attrs['localdate'] = now.strftime '%F' attrs['localyear'] ||= now.year.to_s end # %Z is OS dependent and may contain characters that aren't UTF-8 encoded (see asciidoctor#2770 and asciidoctor.js#23) localtime = (attrs['localtime'] ||= now.strftime %(%T #{now.utc_offset == 0 ? 'UTC' : '%z'})) attrs['localdatetime'] ||= %(#{localdate} #{localtime}) # docdate, doctime and docdatetime should default to localdate, localtime and localdatetime if not otherwise set input_mtime = source_date_epoch || input_mtime || now if (docdate = attrs['docdate']) attrs['docyear'] ||= ((docdate.index '-') == 4 ? (docdate.slice 0, 4) : nil) else docdate = attrs['docdate'] = input_mtime.strftime '%F' attrs['docyear'] ||= input_mtime.year.to_s end # %Z is OS dependent and may contain characters that aren't UTF-8 encoded (see asciidoctor#2770 and asciidoctor.js#23) doctime = (attrs['doctime'] ||= input_mtime.strftime %(%T #{input_mtime.utc_offset == 0 ? 'UTC' : '%z'})) attrs['docdatetime'] ||= %(#{docdate} #{doctime}) nil end