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