Class: Facter::Util::CFPropertyList::CFDate

### Home Classes Methods

### In Files

- lib/facter/util/cfpropertylist/lib/rbCFTypes.rb

### Parent

Facter::Util::CFPropertyList::CFType

### Methods

- ::date_string
- ::new
- ::parse_date
- #get_value
- #set_value
- #to_binary
- #to_xml

### Files

- LICENSE
- Rakefile
- THANKS

### Class/Module Index

Quicksearch

- Facter
- Facter::Application
- Facter::Manufacturer
- Facter::Memory
- Facter::NetMask
- Facter::Util
- Facter::Util::CFPropertyList
- Facter::Util::CFPropertyList::CFArray
- Facter::Util::CFPropertyList::CFBoolean
- Facter::Util::CFPropertyList::CFData
- Facter::Util::CFPropertyList::CFDate
- Facter::Util::CFPropertyList::CFDictionary
- Facter::Util::CFPropertyList::CFInteger
- Facter::Util::CFPropertyList::CFReal
- Facter::Util::CFPropertyList::CFString
- Facter::Util::CFPropertyList::CFType
- Facter::Util::CFPropertyList::XML
- Facter::Util::Collection
- Facter::Util::CompositeLoader
- Facter::Util::Config
- Facter::Util::Confine
- Facter::Util::DirectoryLoader
- Facter::Util::DirectoryLoader::NoSuchDirectoryError
- Facter::Util::EC2
- Facter::Util::Fact
- Facter::Util::FileRead
- Facter::Util::IP
- Facter::Util::IP::Windows
- Facter::Util::IP::Windows::Bindings4
- Facter::Util::IP::Windows::Bindings6
- Facter::Util::Loader
- Facter::Util::Macaddress
- Facter::Util::Macaddress::Darwin
- Facter::Util::Macaddress::Windows
- Facter::Util::Macosx
- Facter::Util::MonkeyPatches
- Facter::Util::MonkeyPatches::Lines
- Facter::Util::NothingLoader
- Facter::Util::Parser
- Facter::Util::Parser::Base
- Facter::Util::Parser::JsonParser
- Facter::Util::Parser::KeyValuePairOutputFormat
- Facter::Util::Parser::NothingParser
- Facter::Util::Parser::PowershellParser
- Facter::Util::Parser::ScriptParser
- Facter::Util::Parser::TextParser
- Facter::Util::Parser::YamlParser
- Facter::Util::Processor
- Facter::Util::Registry
- Facter::Util::Resolution
- Facter::Util::SolarisZones
- Facter::Util::Uptime
- Facter::Util::Values
- Facter::Util::Virtual
- Facter::Util::Vlans
- Facter::Util::WMI
- Facter::Util::Xendomains
- Plist
- Plist::Emit
- Plist::Listener
- Plist::PArray
- Plist::PData
- Plist::PDate
- Plist::PDict
- Plist::PFalse
- Plist::PInteger
- Plist::PKey
- Plist::PList
- Plist::PReal
- Plist::PString
- Plist::PTag
- Plist::PTrue
- Plist::StreamParser
- CFFormatError
- CFPlistError
- CFTypeError
- IO
- Object
- String

No matching classes.

# Facter::Util::CFPropertyList::CFDate

This class holds Time values. While Apple uses seconds since 2001, the rest of the world uses seconds since 1970. So if you access value directly, you get the Time class. If you access via get_value you either geht the timestamp or the Apple timestamp

### Constants

DATE_DIFF_APPLE_UNIX
TIMESTAMP_APPLE
TIMESTAMP_UNIX

### Public Class Methods

date_string(val) click to toggle source

create a XML date strimg from a time object

    # File lib/facter/util/cfpropertylist/lib/rbCFTypes.rb, line 84
    def CFDate.date_string(val)
      # 2009-05-13T20:23:43Z
      val.getutc.strftime("%Y-%m-%dT%H:%M:%SZ")
    end

new(value = nil,format=CFDate::TIMESTAMP_UNIX) click to toggle source

set value to defined state

    # File lib/facter/util/cfpropertylist/lib/rbCFTypes.rb, line 98
    def initialize(value = nil,format=CFDate::TIMESTAMP_UNIX)
      if(value.is_a?(Time) || value.nil?) then
        @value = value.nil? ? Time.now : value
      elsif value.instance_of? Date
        @value = Time.utc(value.year, value.month, value.day, 0, 0, 0)
      elsif value.instance_of? DateTime
        @value = value.to_time.utc
      else
        set_value(value,format)
      end
    end

parse_date(val) click to toggle source

parse a XML date string

    # File lib/facter/util/cfpropertylist/lib/rbCFTypes.rb, line 90
    def CFDate.parse_date(val)
      # 2009-05-13T20:23:43Z
      val =~ %{^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})Z$}
      year,month,day,hour,min,sec = $1, $2, $3, $4, $5, $6
      return Time.utc(year,month,day,hour,min,sec).getlocal
    end

### Public Instance Methods

get_value(format=CFDate::TIMESTAMP_UNIX) click to toggle source

get timestamp, either UNIX or Apple timestamp

    # File lib/facter/util/cfpropertylist/lib/rbCFTypes.rb, line 120
    def get_value(format=CFDate::TIMESTAMP_UNIX)
      if(format == CFDate::TIMESTAMP_UNIX) then
        @value.to_i
      else
        @value.to_f - CFDate::DATE_DIFF_APPLE_UNIX
      end
    end

set_value(value,format=CFDate::TIMESTAMP_UNIX) click to toggle source

set value with timestamp, either Apple or UNIX

    # File lib/facter/util/cfpropertylist/lib/rbCFTypes.rb, line 111
    def set_value(value,format=CFDate::TIMESTAMP_UNIX)
      if(format == CFDate::TIMESTAMP_UNIX) then
        @value = Time.at(value)
      else
        @value = Time.at(value + CFDate::DATE_DIFF_APPLE_UNIX)
      end
    end

to_binary(bplist) click to toggle source

convert to binary

    # File lib/facter/util/cfpropertylist/lib/rbCFTypes.rb, line 136
    def to_binary(bplist)
      bplist.date_to_binary(@value)
    end

to_xml(parser) click to toggle source

convert to XML

    # File lib/facter/util/cfpropertylist/lib/rbCFTypes.rb, line 129
    def to_xml(parser)
      n = parser.new_node('date')
      n = parser.append_node(n, parser.new_text(CFDate::date_string(@value)))
      n
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.