class Puppet::Pops::Types::PTimestampType

Constants

DEFAULT

Public Class Methods

new_function(type) click to toggle source
   # File lib/puppet/pops/types/p_timestamp_type.rb
12     def self.new_function(type)
13       @new_function ||= Puppet::Functions.create_loaded_function(:new_timestamp, type.loader) do
14         local_types do
15           type 'Formats = Variant[String[2],Array[String[2], 1]]'
16         end
17 
18         dispatch :now do
19         end
20 
21         dispatch :from_seconds do
22           param 'Variant[Integer,Float]', :seconds
23         end
24 
25         dispatch :from_string do
26           param           'String[1]', :string
27           optional_param  'Formats',   :format
28           optional_param  'String[1]', :timezone
29         end
30 
31         dispatch :from_string_hash do
32           param <<-TYPE, :hash_arg
33             Struct[{
34               string => String[1],
35               Optional[format] => Formats,
36               Optional[timezone] => String[1]
37             }]
38           TYPE
39         end
40 
41         def now
42           Time::Timestamp.now
43         end
44 
45         def from_string(string, format = :default, timezone = nil)
46           Time::Timestamp.parse(string, format, timezone)
47         end
48 
49         def from_string_hash(args_hash)
50           Time::Timestamp.from_hash(args_hash)
51         end
52 
53         def from_seconds(seconds)
54           Time::Timestamp.new((seconds * Time::NSECS_PER_SEC).to_i)
55         end
56       end
57     end
register_ptype(loader, ir) click to toggle source
   # File lib/puppet/pops/types/p_timestamp_type.rb
 5 def self.register_ptype(loader, ir)
 6   create_ptype(loader, ir, 'ScalarType',
 7     'from' => { KEY_TYPE => POptionalType.new(PTimestampType::DEFAULT), KEY_VALUE => nil },
 8     'to' => { KEY_TYPE => POptionalType.new(PTimestampType::DEFAULT), KEY_VALUE => nil }
 9   )
10 end

Public Instance Methods

from_seconds(seconds) click to toggle source
   # File lib/puppet/pops/types/p_timestamp_type.rb
53 def from_seconds(seconds)
54   Time::Timestamp.new((seconds * Time::NSECS_PER_SEC).to_i)
55 end
from_string(string, format = :default, timezone = nil) click to toggle source
   # File lib/puppet/pops/types/p_timestamp_type.rb
45 def from_string(string, format = :default, timezone = nil)
46   Time::Timestamp.parse(string, format, timezone)
47 end
from_string_hash(args_hash) click to toggle source
   # File lib/puppet/pops/types/p_timestamp_type.rb
49 def from_string_hash(args_hash)
50   Time::Timestamp.from_hash(args_hash)
51 end
generalize() click to toggle source
   # File lib/puppet/pops/types/p_timestamp_type.rb
59 def generalize
60   DEFAULT
61 end
impl_class() click to toggle source
   # File lib/puppet/pops/types/p_timestamp_type.rb
63 def impl_class
64   Time::Timestamp
65 end
instance?(o, guard = nil) click to toggle source
   # File lib/puppet/pops/types/p_timestamp_type.rb
67 def instance?(o, guard = nil)
68   o.is_a?(Time::Timestamp) && o >= @from && o <= @to
69 end
now() click to toggle source
   # File lib/puppet/pops/types/p_timestamp_type.rb
41 def now
42   Time::Timestamp.now
43 end