Class: Time

Inherits:
Object
  • Object
show all
Defined in:
lib/sixarm_ruby_time_stamp/time.rb

Overview

Please see README

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.stamp(format = self.stamp_format) ⇒ Object

Shorthand for Time.now.stamp

Example:

Time.stamp
=> "2020-12-31T12:59:59Z"

Return: [String] Time.now time stamp string



35
36
37
# File 'lib/sixarm_ruby_time_stamp/time.rb', line 35

def self.stamp(format = self.stamp_format)
  now.stamp(format)
end

.stamp_formatObject

Get class-scope stamp format string

Example:

Time.stamp_format => "%Y-%m-%dT%H:%M:%S.%NZ"

Return: [String] stamp format string



69
70
71
# File 'lib/sixarm_ruby_time_stamp/time.rb', line 69

def self.stamp_format
  @@stamp_format ||= '%Y-%m-%dT%H:%M:%S.%NZ'
end

.stamp_format=(format) ⇒ Object

Set class-scope stamp format string

Example:

Time.stamp_format = "%Y-%m-%dT%H:%M:%S.%NZ"

Return: [String] stamp format string



81
82
83
# File 'lib/sixarm_ruby_time_stamp/time.rb', line 81

def self.stamp_format=(format)
  @@stamp_format = format
end

.stamp_format_defaultObject

Get class-scope stamp format default string

Example:

Time.stamp_format_default => "%Y-%m-%dT%H:%M:%S.%NZ"

Return: [String] stamp format default string



93
94
95
# File 'lib/sixarm_ruby_time_stamp/time.rb', line 93

def self.stamp_format_default
  "%Y-%m-%dT%H:%M:%S.%NZ"
end

Instance Method Details

#stamp(format = stamp_format) ⇒ Object

Create a time stamp string using the default format “YYYY-MM-DDTHH:MM:SSZ”

This standard format is specified in IETF RFC 3339 and ISO 8601.

Example:

time = Time.now
time.stamp
=> "2020-12-31T12:59:59Z"

Return: [String] a time stamp string



22
23
24
# File 'lib/sixarm_ruby_time_stamp/time.rb', line 22

def stamp(format = stamp_format)
  getutc.strftime(format)
end

#stamp_formatObject

Get stamp format string

Example:

time.stamp_format => "%Y-%m-%dT%H:%M:%S.%NZ"

Return: [String] stamp format string



47
48
49
# File 'lib/sixarm_ruby_time_stamp/time.rb', line 47

def stamp_format
  @stamp_format ||= '%Y-%m-%dT%H:%M:%S.%NZ'
end

#stamp_format=(format) ⇒ Object

Set stamp format string

Example:

time.stamp_format = "%Y-%m-%dT%H:%M:%S.%NZ"


57
58
59
# File 'lib/sixarm_ruby_time_stamp/time.rb', line 57

def stamp_format=(format)
  @stamp_format = format
end