Module: TestBench::Telemetry::Controls::Time

Defined in:
lib/test_bench/telemetry/controls/time.rb

Defined Under Namespace

Modules: Elapsed, ISO8601, Offset, Random

Constant Summary collapse

Other =
Offset

Class Method Summary collapse

Class Method Details

.example(offset_milliseconds: nil, offset_nanoseconds: nil) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/test_bench/telemetry/controls/time.rb', line 5

def self.example(offset_milliseconds: nil, offset_nanoseconds: nil)
  if offset_nanoseconds.nil?
    offset_milliseconds ||= 0
    offset_nanoseconds = offset_milliseconds * 1_000_000
  end

  nanoseconds = 111_111_111
  remaining_offset, additional_nanoseconds = offset_nanoseconds.divmod(1_000_000_000 - nanoseconds)
  nanoseconds += additional_nanoseconds
  microseconds = Rational(nanoseconds, 1_000)

  if remaining_offset.zero?
    seconds = 11
  else
    remaining_offset, seconds = remaining_offset.divmod(60)
  end

  if remaining_offset.zero?
    minutes = 11
  else
    remaining_offset, minutes = remaining_offset.divmod(60)
  end

  if remaining_offset.zero?
    hours = 11
  else
    remaining_offset, hours = remaining_offset.divmod(24)
  end

  if remaining_offset.zero?
    day = 1
  else
    remaining_offset, day = remaining_offset.divmod(28)
    day += 1
  end

  if remaining_offset.zero?
    month = 1
  else
    remaining_offset, month = remaining_offset.divmod(12)
    month += 1
  end

  year = 2000
  if not remaining_offset.zero?
    year += remaining_offset
  end

  ::Time.utc(year, month, day, hours, minutes, seconds, microseconds)
end

.other_exampleObject



56
57
58
# File 'lib/test_bench/telemetry/controls/time.rb', line 56

def self.other_example
  Other.example
end

.randomObject



60
61
62
# File 'lib/test_bench/telemetry/controls/time.rb', line 60

def self.random
  Random.example
end