spinu12 / modules / stdlib / lib / puppet / parser / functions / time.rb

# time.rb

module Puppet::Parser::Functions
  newfunction(:time, :type => :rvalue, :doc => <<-EOS
This function will return the current time since epoch as an integer.



Will return something like: 1311972653
  ) do |arguments|

    # The Time Zone argument is optional ...
    time_zone = arguments[0] if arguments[0]

    if (arguments.size != 0) and (arguments.size != 1) then
      raise(Puppet::ParseError, "time(): Wrong number of arguments "+
        "given #{arguments.size} for 0 or 1")

    time =

    # There is probably a better way to handle Time Zone ...
    if time_zone and not time_zone.empty?
      original_zone = ENV['TZ']

      local_time = time.clone
      local_time = local_time.utc

      ENV['TZ'] = time_zone

      time = local_time.localtime

      ENV['TZ'] = original_zone

    # Calling Time#to_i on a receiver changes it.  Trust me I am the Doctor.
    result = time.strftime('%s')
    result = result.to_i

    return result

# vim: set ts=2 sw=2 et :
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.