Class: SafeDb::TimeStamp
- Inherits:
-
Object
- Object
- SafeDb::TimeStamp
- Includes:
- Singleton
- Defined in:
- lib/utils/time/timestamp.rb
Overview
This stamp sits at the centre of a fundamental DevOps pattern concerned with infrastructure provisioning and configuraion management.
The central idea behind the pattern is to link every infrastructure object created during a branch with a reference accurate to the nearest centi-second denoting the moment the software runtime (branch) began.
Instance Attribute Summary collapse
-
#time_now ⇒ Object
readonly
Returns the value of attribute time_now.
Class Method Summary collapse
-
.ddd ⇒ Object
Return three character abbreviated day of week.
-
.fetch ⇒ String
Fetch the double barreled time stamp that is an amalgam of the human readable time now and a machine time representation from the moment this class was initialized.
-
.grab ⇒ String
Grab the double barreled time stamp that is an amalgam of the human readable time now and a machine time representation from the moment this class was initialized.
-
.hh ⇒ Object
Return two digit (character) hour of day from 00 to 23.
-
.hhmm ⇒ Object
Return the 4 digit amalgam of the hour and minute using the 24 hour clock.
-
.hhmm_sst ⇒ Object
Return the time of day to a TENTH of a second accuracy.
-
.human_readable ⇒ String
Fetch the human readable time stamp.
-
.jjj ⇒ Object
————————————————- – # Return 3 digit julian day of year [001] to [366].
-
.log_instance_time ⇒ Object
Log segments of time pertaining to the time stamp.
-
.mm ⇒ Object
Return two digit minute of hour from [00] to [59].
-
.mmm ⇒ Object
Return three character abbreviated month name.
-
.mo ⇒ Object
Return two digit [mo] month index from 01 to 12.
-
.previous_month_chars(this_month_index, this_4digit_year) ⇒ Object
Given two integer parameters (month index and 4 digit year) representing the month in question this method returns the [PREVIOUS MONTHS] character amalgam in the format [yymo_mmm] where.
-
.readable ⇒ String
Fetch the human readable time denoting the weekday, month day, month, year and the time (accurate to the nearest minute).
-
.ss ⇒ Object
Return two digit second of minute from [00] to [59].
-
.sst ⇒ Object
Return a [3 digit] second and tenth of second representation.
-
.y ⇒ Object
Return the [one] digit year (eg 9 for 2019).
-
.yjjj ⇒ Object
Return 4 digit amalgam of year and julian day.
-
.yjjjhhmmsst ⇒ Object
Return the time of day to a TENTH of a second accuracy via a string timestamp with zero separation.
-
.yy ⇒ Object
Return the [two] digit year (eg 19 for 2019).
-
.yyjjj ⇒ Object
Return 5 digit amalgam of year and julian day.
-
.yyjjj_hhmm_ss_nanosec ⇒ String
Return a string timestampt that is a period separated amalgam of the 2 digit year, 3 digit julian day, 2 digit hour, 2 digit minute, 2 digit second and 9 digit nanosecond.
-
.yyjjj_hhmm_sst ⇒ Object
Return a string timestampt that is a period separated amalgam of the 2 digit year, 3 digit julian day, 2 digit hour, 2 digit minute, 2 digit second and 1 digit rounded down tenth of second.
-
.yyjjjhhmm ⇒ Object
Return the time of day to a single minute accuracy via a string timestamp with zero separation.
-
.yyjjjhhmmsst ⇒ Object
Return the time of day to a TENTH of a second accuracy via a string timestamp with zero separation.
-
.yymo_mmm ⇒ Object
- yymo_mmm
-
returns an amalgam of.
-
.yymo_mmm_prev ⇒ Object
Using the current class time this method returns the character amalgam for the [PREVIOUS MONTH] in the format [yymo_mmm] where.
-
.yyyy ⇒ Object
Return the [four] digit year (eg 2019) that we are currently in.
-
.zone ⇒ Object
Return the Rubyfied time zone being used.
Instance Method Summary collapse
-
#initialize ⇒ TimeStamp
constructor
This singleton (one instance) class sets the time just once.
Constructor Details
#initialize ⇒ TimeStamp
This singleton (one instance) class sets the time just once.
499 500 501 |
# File 'lib/utils/time/timestamp.rb', line 499 def initialize @time_now = Time.now; end |
Instance Attribute Details
#time_now ⇒ Object (readonly)
Returns the value of attribute time_now.
16 17 18 |
# File 'lib/utils/time/timestamp.rb', line 16 def time_now @time_now end |
Class Method Details
.ddd ⇒ Object
Return three character abbreviated day of week.
38 39 40 |
# File 'lib/utils/time/timestamp.rb', line 38 def self.ddd return TimeStamp.instance.time_now.strftime( "%a" ).downcase end |
.fetch ⇒ String
Fetch the double barreled time stamp that is an amalgam of the human readable time now and a machine time representation from the moment this class was initialized.
See the yyjjj_hhmm_ss_nanosec method for documentation of the nanosecond accurate time stamp.
425 426 427 |
# File 'lib/utils/time/timestamp.rb', line 425 def self.fetch return "#{Time.now.ctime} ( #{yyjjj_hhmm_ss_nanosec} )" end |
.grab ⇒ String
Grab the double barreled time stamp that is an amalgam of the human readable time now and a machine time representation from the moment this class was initialized.
On Friday June the 8th at about 6:26 pm.
Fri Jun 8 18:26:17 2018 ( 18159.1826.138 )
See the yyjjj_hhmm_sst method for documentation of stamp that is accurate to the tenth of a second.
455 456 457 458 459 |
# File 'lib/utils/time/timestamp.rb', line 455 def self.grab time_with_consecutive_spaces = Time.now.ctime human_readable_str = time_with_consecutive_spaces.gsub( " ", " " ) return "#{human_readable_str} ( #{yyjjj_hhmm_sst} )" end |
.hh ⇒ Object
Return two digit (character) hour of day from 00 to 23.
47 48 49 |
# File 'lib/utils/time/timestamp.rb', line 47 def self.hh return TimeStamp.instance.time_now.strftime "%H" end |
.hhmm ⇒ Object
Return the 4 digit amalgam of the hour and minute using the 24 hour clock.
240 241 242 |
# File 'lib/utils/time/timestamp.rb', line 240 def self.hhmm return "#{hh}#{mm}" end |
.hhmm_sst ⇒ Object
Return the time of day to a TENTH of a second accuracy.
- 8
-
characters will always be returned with the 5th one
being the (period) separator.
The first (separated) segment delivers a hhmm 24 hour clock representation of the stamped time.
The 3 digits of the second segment comprise of
second of minute => 2 digits | [00] to [59]
tenth of second => 1 digit from [0] to [9]
266 267 268 |
# File 'lib/utils/time/timestamp.rb', line 266 def self.hhmm_sst return "#{hhmm}.#{sst}" end |
.human_readable ⇒ String
Fetch the human readable time stamp.
409 410 411 |
# File 'lib/utils/time/timestamp.rb', line 409 def self.human_readable return "#{Time.now.ctime} #{yyjjj_hhmm_sst}" end |
.jjj ⇒ Object
————————————————- – # Return 3 digit julian day of year [001] to [366]. – # ————————————————- – #
131 132 133 |
# File 'lib/utils/time/timestamp.rb', line 131 def self.jjj return TimeStamp.instance.time_now.strftime "%j" end |
.log_instance_time ⇒ Object
move method contents into test class
Log segments of time pertaining to the time stamp.
471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 |
# File 'lib/utils/time/timestamp.rb', line 471 def self.log_instance_time log.info(x) { "activity timestamp is #{yyjjj_hhmm_sst} representing #{TimeStamp.instance.time_now.ctime}" } log.debug(x) { "[stamp] -------------- => -------------------------------- #" } log.debug(x) { "[stamp] eco time stamp => [#{TimeStamp.instance.time_now.ctime}]" } log.debug(x) { "[stamp] -------------- => -------------------------------- #" } log.debug(x) { "[stamp] Univ Time Zone => #{zone}" } log.debug(x) { "[stamp] Month Index is => #{mo}" } log.debug(x) { "[stamp] Month Name is => #{mmm}" } log.debug(x) { "[stamp] Day Of Week is => #{ddd}" } log.debug(x) { "[stamp] -------------- => -------------------------------- #" } log.debug(x) { "[stamp] Two Digit Year => #{yy}" } log.debug(x) { "[stamp] Julian Cal Day => #{jjj}" } log.debug(x) { "[stamp] Yr and Jul Day => #{yyjjj}" } log.debug(x) { "[stamp] Hour of Theday => #{hh}" } log.debug(x) { "[stamp] Minute of Hour => #{mm}" } log.debug(x) { "[stamp] Hour + Minute => #{hhmm}" } log.debug(x) { "[stamp] Second of Min => #{ss}" } log.debug(x) { "[stamp] 600 Min Slices => #{sst}" } log.debug(x) { "[stamp] -------------- => -------------------------------- #" } log.debug(x) { "[stamp] The Time Stamp => #{yyjjj_hhmm_sst}" } log.debug(x) { "[stamp] -------------- => -------------------------------- #" } end |
.mm ⇒ Object
Return two digit minute of hour from [00] to [59].
55 56 57 |
# File 'lib/utils/time/timestamp.rb', line 55 def self.mm return TimeStamp.instance.time_now.strftime "%M" end |
.mmm ⇒ Object
Return three character abbreviated month name.
29 30 31 |
# File 'lib/utils/time/timestamp.rb', line 29 def self.mmm return TimeStamp.instance.time_now.strftime( "%b" ).downcase end |
.mo ⇒ Object
Return two digit [mo] month index from 01 to 12.
21 22 23 |
# File 'lib/utils/time/timestamp.rb', line 21 def self.mo return TimeStamp.instance.time_now.strftime "%m" end |
.previous_month_chars(this_month_index, this_4digit_year) ⇒ Object
Given two integer parameters (month index and 4 digit year) representing the month in question this method returns the [PREVIOUS MONTHS] character amalgam in the format [yymo_mmm] where
=> yy | previous month's two-digit year
=> mo | previous month's two-digit month index
=> . | a period (separator)
=> mmm | previous month's abbreviated month name
Example 1 (Simple)
returns char => 1907.jul
4 parameters => 8, 2019
representing => August, 2019
Example 2 (Last Year)
returns char => 1812.dec
4 parameters => 1, 2019
representing => January, 2019
178 179 180 181 182 183 184 185 186 187 188 |
# File 'lib/utils/time/timestamp.rb', line 178 def self.previous_month_chars this_month_index, this_4digit_year prev_month_index = this_month_index == 1 ? 12 : ( this_month_index - 1 ) prev_2dig_mn_pad = sprintf '%02d', prev_month_index prev_4digit_year = this_month_index == 1 ? ( this_4digit_year - 1 ) : this_4digit_year prev_twodigit_yr = "#{prev_4digit_year.to_s}"[2..-1] prev_months_name = Date::ABBR_MONTHNAMES[prev_month_index].downcase return "#{prev_twodigit_yr}#{prev_2dig_mn_pad}.#{prev_months_name}" end |
.readable ⇒ String
Fetch the human readable time denoting the weekday, month day, month, year and the time (accurate to the nearest minute).
435 436 437 438 |
# File 'lib/utils/time/timestamp.rb', line 435 def self.readable time_with_consecutive_spaces = Time.now.ctime return time_with_consecutive_spaces.gsub( " ", " " ) end |
.ss ⇒ Object
Return two digit second of minute from [00] to [59].
63 64 65 |
# File 'lib/utils/time/timestamp.rb', line 63 def self.ss return TimeStamp.instance.time_now.strftime "%S" end |
.sst ⇒ Object
Return a [3 digit] second and tenth of second representation.
The final digit is derived from the 1000 sliced millisecond of second running from 000 to 999.
Truncation (Not Rounding)
The [final] digit is acquired by TRUNCATING (chopping off) the last 2 of the 3 millisecond digits. No rounding is applied.
The 3 returned digits comprise of the
-
second of minute => 2 digits | [00] to [59] (and)
-
tenth of second => 1 digit from [0] to [9]
95 96 97 98 |
# File 'lib/utils/time/timestamp.rb', line 95 def self.sst millisec_string = TimeStamp.instance.time_now.strftime "%L" return "#{ss}#{millisec_string[0]}" end |
.y ⇒ Object
Return the [one] digit year (eg 9 for 2019). that we are currently in.
114 115 116 |
# File 'lib/utils/time/timestamp.rb', line 114 def self.y return TimeStamp.instance.time_now.strftime("%Y")[3..-1] end |
.yjjj ⇒ Object
Return 4 digit amalgam of year and julian day.
eg [9003] for [January 3rd 2019]
228 229 230 |
# File 'lib/utils/time/timestamp.rb', line 228 def self.yjjj return "#{y}#{jjj}" end |
.yjjjhhmmsst ⇒ Object
Return the time of day to a TENTH of a second accuracy via a string timestamp with zero separation.
The timestampt returned is an amalgam of
-
a 1 digit year
-
a 3 digit julian day
-
a 2 digit hourn
-
a 2 digit minute
-
a 2 digit second and finally
-
a 1 digit (rounded down) tenth of a second
The 3 digits of the second segment comprise of
-
second of minute => 2 digits | [00] to [59]
-
tenth of second => 1 digit from [0] to [9]
356 357 358 |
# File 'lib/utils/time/timestamp.rb', line 356 def self.yjjjhhmmsst return "#{yjjj}#{hhmm}#{sst}" end |
.yy ⇒ Object
Return the [two] digit year (eg 19 for 2019). that we are currently in.
105 106 107 |
# File 'lib/utils/time/timestamp.rb', line 105 def self.yy return TimeStamp.instance.time_now.strftime("%Y")[2..-1] end |
.yyjjj ⇒ Object
Return 5 digit amalgam of year and julian day.
eg [19003] for [January 3rd 2019]
221 222 223 |
# File 'lib/utils/time/timestamp.rb', line 221 def self.yyjjj return "#{yy}#{jjj}" end |
.yyjjj_hhmm_ss_nanosec ⇒ String
Return a string timestampt that is a period separated amalgam of the 2 digit year, 3 digit julian day, 2 digit hour, 2 digit minute, 2 digit second and 9 digit nanosecond.
As per the above example, the time returned
-
is the 836592034 nanosecond
-
of the 42nd second
-
of the 25th minute
-
of the 17th hour
-
of the 3rd day
-
of the 20th year
-
of the 21st century
399 400 401 402 |
# File 'lib/utils/time/timestamp.rb', line 399 def self.yyjjj_hhmm_ss_nanosec nanosec_str = TimeStamp.instance.time_now.strftime "%9N" return "#{yyjjj}.#{hhmm}.#{ss}.#{nanosec_str}" end |
.yyjjj_hhmm_sst ⇒ Object
Return a string timestampt that is a period separated amalgam of the 2 digit year, 3 digit julian day, 2 digit hour, 2 digit minute, 2 digit second and 1 digit rounded down tenth of second.
Return the time of day to a TENTH of a second accuracy.
- 8
-
characters will always be returned with the 5th one
being the (period) separator.
The first (separated) segment delivers a hhmm 24 hour clock representation of the stamped time.
The 3 digits of the second segment comprise of
-
second of minute => 2 digits | [00] to [59]
-
tenth of second => 1 digit from [0] to [9]
296 297 298 |
# File 'lib/utils/time/timestamp.rb', line 296 def self.yyjjj_hhmm_sst return "#{yyjjj}.#{hhmm}.#{sst}" end |
.yyjjjhhmm ⇒ Object
Return the time of day to a single minute accuracy via a string timestamp with zero separation.
The timestampt returned is an amalgam of
-
a 2 digit year
-
a 3 digit julian day
-
a 2 digit hourn
-
a 2 digit minute
371 372 373 |
# File 'lib/utils/time/timestamp.rb', line 371 def self.yyjjjhhmm return "#{yyjjj}#{hhmm}" end |
.yyjjjhhmmsst ⇒ Object
Return the time of day to a TENTH of a second accuracy via a string timestamp with zero separation.
The timestampt returned is an amalgam of
-
a 2 digit year
-
a 3 digit julian day
-
a 2 digit hourn
-
a 2 digit minute
-
a 2 digit second and finally
-
a 1 digit (rounded down) tenth of a second
The 3 digits of the second segment comprise of
-
second of minute => 2 digits | [00] to [59]
-
tenth of second => 1 digit from [0] to [9]
326 327 328 |
# File 'lib/utils/time/timestamp.rb', line 326 def self.yyjjjhhmmsst return "#{yyjjj}#{hhmm}#{sst}" end |
.yymo_mmm ⇒ Object
- yymo_mmm
-
returns an amalgam of
=> the two-digit year
=> the two-digit month index (starting at 01)
=> a period (separator)
=> the abbreviated month name
147 148 149 |
# File 'lib/utils/time/timestamp.rb', line 147 def self.yymo_mmm return "#{yy}#{mo}.#{mmm}" end |
.yymo_mmm_prev ⇒ Object
Using the current class time this method returns the character amalgam for the [PREVIOUS MONTH] in the format [yymo_mmm] where
=> yy | last month's two-digit year
=> mo | last month's two-digit month index
=> . | a period (separator)
=> mmm | last month's abbreviated month name
Example 1 (Simple)
returns => 1907.jul
if this month is => August 2019
Example 2 (Last Year)
returns => 1812.dec
if this month is => January 2019
214 215 216 |
# File 'lib/utils/time/timestamp.rb', line 214 def self.yymo_mmm_prev return previous_month_chars mo.to_i, yyyy.to_i end |
.yyyy ⇒ Object
Return the [four] digit year (eg 2019) that we are currently in.
123 124 125 |
# File 'lib/utils/time/timestamp.rb', line 123 def self.yyyy return TimeStamp.instance.time_now.strftime("%Y") end |
.zone ⇒ Object
Return the Rubyfied time zone being used.
463 464 465 |
# File 'lib/utils/time/timestamp.rb', line 463 def self.zone return TimeStamp.instance.time_now.zone end |