vishnu-standard-time 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 59b1b839f360e681af0cf1048575aca912a8590339723b3932dc63f9b2daa648
4
+ data.tar.gz: 177ad7aa34b141327d871b4e5ef5547375716c245e719af0ca0db1de56b91c57
5
+ SHA512:
6
+ metadata.gz: a86aad8123fc755334d07e62442108fc6051a284b087c1e00492e10430c1f6459fdf8ad2fd8cc026b4b220f78a4fb188abcc43306f42d2ed58b38ea8d8eb59c6
7
+ data.tar.gz: dde90f5af4d50f7aa97030d15c88902bcd82c11842f962559074b0bba1eda2e5aa4f11f7bf4041cf15c197b44dec5c8df31249b40bae730675c8778bc11f303d
data/README.md ADDED
@@ -0,0 +1,14 @@
1
+ # vishnu-standard-time
2
+
3
+ Ruby gem for **Vishnu Standard Time (VST)**.
4
+
5
+ ```bash
6
+ gem install vishnu-standard-time
7
+ ```
8
+
9
+ ```ruby
10
+ require "vishnu/standard_time"
11
+
12
+ parts = Vishnu::StandardTime.now
13
+ puts Vishnu::StandardTime.format_vst(parts)
14
+ ```
@@ -0,0 +1,121 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Vishnu
4
+ module StandardTime
5
+ VST_SPEC_VERSION = "0.1.0"
6
+ VST_EPOCH_UNIX_MS = 1_767_225_600_000
7
+ MS_PER_DAY = 86_400_000
8
+ FLOWS_PER_SECOND = 3
9
+ FLOWS_PER_MINUTE = 180
10
+ FLOWS_PER_DAY = 259_200
11
+ FLOW_LENGTH_MS_TEXT = "333⅓"
12
+ VICKS_PER_DAY = 100_000
13
+ MS_PER_VICK = 864
14
+
15
+ Parts = Struct.new(
16
+ :day,
17
+ :day_ms,
18
+ :flow,
19
+ :flow_of_minute,
20
+ :second_of_day,
21
+ :percent_of_day,
22
+ :vick,
23
+ :pulse,
24
+ :unix_ms,
25
+ :source,
26
+ keyword_init: true
27
+ )
28
+
29
+ module_function
30
+
31
+ def from_unix_ms(unix_ms)
32
+ ms = Integer(unix_ms)
33
+ day, day_ms = (ms - VST_EPOCH_UNIX_MS).divmod(MS_PER_DAY)
34
+ parts_from_day_ms(day, day_ms, unix_ms: ms, source: "standard")
35
+ end
36
+
37
+ def from_day_ms(day, day_ms)
38
+ parts_from_day_ms(Integer(day), Integer(day_ms))
39
+ end
40
+
41
+ def parts_from_day_ms(day, day_ms, unix_ms: nil, source: "standard")
42
+ raise ArgumentError, "day_ms must be from 0 through 86399999" if day_ms.negative? || day_ms >= MS_PER_DAY
43
+
44
+ flow = (day_ms * FLOWS_PER_DAY) / MS_PER_DAY
45
+ Parts.new(
46
+ day: day,
47
+ day_ms: day_ms,
48
+ flow: flow,
49
+ flow_of_minute: flow % FLOWS_PER_MINUTE,
50
+ second_of_day: day_ms / 1000,
51
+ percent_of_day: (day_ms.to_f / MS_PER_DAY) * 100,
52
+ vick: day_ms / MS_PER_VICK,
53
+ pulse: day_ms % MS_PER_VICK,
54
+ unix_ms: unix_ms,
55
+ source: source
56
+ )
57
+ end
58
+
59
+ def now
60
+ from_unix_ms((Time.now.to_f * 1000).floor)
61
+ end
62
+
63
+ def local_now(time = Time.now)
64
+ day_ms = ((time.hour * 60 + time.min) * 60 + time.sec) * 1000 + (time.usec / 1000)
65
+ local_midnight_as_utc = Time.utc(time.year, time.month, time.day)
66
+ epoch = Time.at(VST_EPOCH_UNIX_MS / 1000, in: "+00:00")
67
+ day = ((local_midnight_as_utc - epoch) / 86_400).floor
68
+ parts_from_day_ms(day, day_ms, unix_ms: (time.to_f * 1000).floor, source: "local")
69
+ end
70
+
71
+ def to_unix_ms(parts)
72
+ VST_EPOCH_UNIX_MS + parts.day * MS_PER_DAY + parts.day_ms
73
+ end
74
+
75
+ def format_vst_day(parts)
76
+ sign = parts.day.negative? ? "-" : "+"
77
+ "D#{sign}#{parts.day.abs.to_s.rjust(6, "0")}"
78
+ end
79
+
80
+ def comma6(value)
81
+ s = value.to_i.to_s.rjust(6, "0")
82
+ "#{s[0, 3]},#{s[3, 3]}"
83
+ end
84
+
85
+ def format_flow_count(parts)
86
+ "#{comma6(parts.flow)} / 259,200 flows"
87
+ end
88
+
89
+ def format_flow_of_minute(parts)
90
+ "FLOW #{parts.flow_of_minute.to_s.rjust(3, "0")} / 179"
91
+ end
92
+
93
+ def format_percent_of_day(parts, digits = 2)
94
+ "%0#{digits + 3}.#{digits}f%% OF DAY" % parts.percent_of_day
95
+ end
96
+
97
+ def format_vst(parts)
98
+ "VST #{format_vst_day(parts)} · #{format_flow_count(parts)} · #{format_percent_of_day(parts)}"
99
+ end
100
+
101
+ def format_vst_precise(parts)
102
+ "VST #{format_vst_day(parts)} · #{format_flow_of_minute(parts)} · #{format_flow_count(parts)} · #{format_percent_of_day(parts)}"
103
+ end
104
+
105
+ def to_h(parts)
106
+ {
107
+ scale: "VST",
108
+ version: VST_SPEC_VERSION,
109
+ day: parts.day.to_s,
110
+ flow: parts.flow,
111
+ flow_of_minute: parts.flow_of_minute,
112
+ flows_per_day: FLOWS_PER_DAY,
113
+ percent_of_day: parts.percent_of_day.round(6),
114
+ text: format_vst(parts),
115
+ day_ms: parts.day_ms.to_s,
116
+ vick: parts.vick,
117
+ pulse: parts.pulse
118
+ }
119
+ end
120
+ end
121
+ end
@@ -0,0 +1,16 @@
1
+ Gem::Specification.new do |spec|
2
+ spec.name = "vishnu-standard-time"
3
+ spec.version = "0.1.0"
4
+ spec.summary = "Vishnu Standard Time (VST): 259,200 flows per day, no AM/PM."
5
+ spec.authors = ["Vishnu"]
6
+ spec.license = "MIT"
7
+ spec.required_ruby_version = ">= 3.0"
8
+ spec.files = Dir["lib/**/*.rb", "README.md", "LICENSE*", "*.gemspec"]
9
+ spec.require_paths = ["lib"]
10
+ spec.homepage = "https://time.vishnu.store"
11
+ spec.metadata = {
12
+ "source_code_uri" => "https://time.vishnu.store",
13
+ "changelog_uri" => "https://time.vishnu.store/.well-known/vst.json"
14
+ }
15
+ spec.add_development_dependency "minitest", "~> 5.25"
16
+ end
metadata ADDED
@@ -0,0 +1,56 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: vishnu-standard-time
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Vishnu
8
+ bindir: bin
9
+ cert_chain: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: minitest
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - "~>"
17
+ - !ruby/object:Gem::Version
18
+ version: '5.25'
19
+ type: :development
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - "~>"
24
+ - !ruby/object:Gem::Version
25
+ version: '5.25'
26
+ executables: []
27
+ extensions: []
28
+ extra_rdoc_files: []
29
+ files:
30
+ - README.md
31
+ - lib/vishnu/standard_time.rb
32
+ - vishnu-standard-time.gemspec
33
+ homepage: https://time.vishnu.store
34
+ licenses:
35
+ - MIT
36
+ metadata:
37
+ source_code_uri: https://time.vishnu.store
38
+ changelog_uri: https://time.vishnu.store/.well-known/vst.json
39
+ rdoc_options: []
40
+ require_paths:
41
+ - lib
42
+ required_ruby_version: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: '3.0'
47
+ required_rubygems_version: !ruby/object:Gem::Requirement
48
+ requirements:
49
+ - - ">="
50
+ - !ruby/object:Gem::Version
51
+ version: '0'
52
+ requirements: []
53
+ rubygems_version: 3.6.9
54
+ specification_version: 4
55
+ summary: 'Vishnu Standard Time (VST): 259,200 flows per day, no AM/PM.'
56
+ test_files: []