Method: Puppet::Pops::Types::PTimestampType.new_function

Defined in:
lib/puppet/pops/types/p_timestamp_type.rb

.new_function(type) ⇒ Object

API:

  • public



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/puppet/pops/types/p_timestamp_type.rb', line 12

def self.new_function(type)
  @new_function ||= Puppet::Functions.create_loaded_function(:new_timestamp, type.loader) do
    local_types do
      type 'Formats = Variant[String[2],Array[String[2], 1]]'
    end

    dispatch :now do
    end

    dispatch :from_seconds do
      param 'Variant[Integer,Float]', :seconds
    end

    dispatch :from_string do
      param           'String[1]', :string
      optional_param  'Formats',   :format
      optional_param  'String[1]', :timezone
    end

    dispatch :from_string_hash do
      param "        Struct[{\n          string => String[1],\n          Optional[format] => Formats,\n          Optional[timezone] => String[1]\n        }]\n      TYPE\n    end\n\n    def now\n      Time::Timestamp.now\n    end\n\n    def from_string(string, format = :default, timezone = nil)\n      Time::Timestamp.parse(string, format, timezone)\n    end\n\n    def from_string_hash(args_hash)\n      Time::Timestamp.from_hash(args_hash)\n    end\n\n    def from_seconds(seconds)\n      Time::Timestamp.new((seconds * Time::NSECS_PER_SEC).to_i)\n    end\n  end\nend\n", :hash_arg