time-beat 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 +7 -0
- data/README.md +44 -0
- data/Rakefile +10 -0
- data/lib/time/beat/version.rb +7 -0
- data/lib/time/beat.rb +54 -0
- metadata +73 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 041bbaf6af9c0895f4dc1412ecc7d34d99a8c2d1fc4629bae24d0bfa7b3cb6b7
|
|
4
|
+
data.tar.gz: 804390afa2d7e0ac94907adf26a8b564fa499ca59b31477047ad230da2d6096b
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: d8fa41e7ee3a2d4dddebb54306d66b5ce3158af0a6bfbe28c9b3b5f1ffa97a749c903494a7c4ed4ccd2eafb5baa52343c1d617e03f9203db687c27cbfce72012
|
|
7
|
+
data.tar.gz: 124fd668f15b8448c3dc86d6b95f846cd1a56692cb8610fe44aead66b174ad811f334a4a0c86168e66b773a80874250d6171dd564822e6ef815244316a25fa35
|
data/README.md
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# Time::Beat
|
|
2
|
+
|
|
3
|
+
[Internet Time][] extension for `Time`
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
gem install time-beat
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
```
|
|
14
|
+
irb(main):001> require 'time/beat'
|
|
15
|
+
=> true
|
|
16
|
+
irb(main):002> Time.now.to_beat.to_s
|
|
17
|
+
=> "@213.819"
|
|
18
|
+
irb(main):003> Time::Beat.now.to_s
|
|
19
|
+
=> "@213.900"
|
|
20
|
+
irb(main):004> Time::Beat.from_time(Time.now).to_s
|
|
21
|
+
=> "@214.086"
|
|
22
|
+
irb(main):005> Time::Beat.from_time(Time.now.utc).to_s
|
|
23
|
+
=> "@214.132"
|
|
24
|
+
irb(main):006> Time::Beat.new(BigDecimal(500.0)).to_time
|
|
25
|
+
=> 2026-05-27 12:00:00 UTC
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Development
|
|
29
|
+
|
|
30
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run
|
|
31
|
+
`bundle exec rake test` to run the tests. You can also run `bin/console` for an
|
|
32
|
+
interactive prompt that will allow you to experiment.
|
|
33
|
+
|
|
34
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
35
|
+
release a new version, update the version number in `version.rb`, and then run
|
|
36
|
+
`bundle exec rake release`, which will create a git tag for the version, push
|
|
37
|
+
git commits and the created tag, and push the `.gem` file to
|
|
38
|
+
[rubygems.org](https://rubygems.org).
|
|
39
|
+
|
|
40
|
+
## Contributing
|
|
41
|
+
|
|
42
|
+
Bug reports and pull requests are welcome at: https://codeberg.org/packrat386/time-beat
|
|
43
|
+
|
|
44
|
+
[Internet Time]: https://gwil.garden/internet-time/
|
data/Rakefile
ADDED
data/lib/time/beat.rb
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "beat/version"
|
|
4
|
+
|
|
5
|
+
require "bigdecimal"
|
|
6
|
+
|
|
7
|
+
class Time
|
|
8
|
+
def to_beat
|
|
9
|
+
Time::Beat.from_time(self)
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
class Beat
|
|
13
|
+
def self.from_time(t)
|
|
14
|
+
t = t.utc
|
|
15
|
+
offset = t.sec + (t.min * 60) + (t.hour * 3600)
|
|
16
|
+
Time::Beat.new(BigDecimal(offset) / BigDecimal("86.4"))
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def self.from_str(s)
|
|
20
|
+
m = /^@(\d{3}\.\d{3})$/.match(s)
|
|
21
|
+
raise "invalid beat string" if m.nil?
|
|
22
|
+
Time::Beat.new(BigDecimal(m.captures.first))
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def self.now
|
|
26
|
+
from_time(Time.now)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
include Comparable
|
|
30
|
+
|
|
31
|
+
attr_accessor :beats
|
|
32
|
+
|
|
33
|
+
def initialize(beats = BigDecimal("0.0"))
|
|
34
|
+
raise "beat value out of range" unless beats >= 0 && beats < 1000
|
|
35
|
+
|
|
36
|
+
self.beats = beats
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def <=>(other)
|
|
40
|
+
beats <=> other.beats
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def to_s
|
|
44
|
+
format("@%03d.%03d", beats.truncate, (1000 * beats.frac).round)
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def to_time
|
|
48
|
+
t = Time.now.utc
|
|
49
|
+
t = Time.new(t.year, t.mon, t.day, 0, 0, 0, in: "UTC")
|
|
50
|
+
t += (86.4 * beats).round
|
|
51
|
+
t
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: time-beat
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Aidan Coyle
|
|
8
|
+
bindir: exe
|
|
9
|
+
cert_chain: []
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
|
+
dependencies:
|
|
12
|
+
- !ruby/object:Gem::Dependency
|
|
13
|
+
name: time
|
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
|
15
|
+
requirements:
|
|
16
|
+
- - ">="
|
|
17
|
+
- !ruby/object:Gem::Version
|
|
18
|
+
version: '0'
|
|
19
|
+
type: :runtime
|
|
20
|
+
prerelease: false
|
|
21
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
22
|
+
requirements:
|
|
23
|
+
- - ">="
|
|
24
|
+
- !ruby/object:Gem::Version
|
|
25
|
+
version: '0'
|
|
26
|
+
- !ruby/object:Gem::Dependency
|
|
27
|
+
name: bigdecimal
|
|
28
|
+
requirement: !ruby/object:Gem::Requirement
|
|
29
|
+
requirements:
|
|
30
|
+
- - ">="
|
|
31
|
+
- !ruby/object:Gem::Version
|
|
32
|
+
version: '0'
|
|
33
|
+
type: :runtime
|
|
34
|
+
prerelease: false
|
|
35
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
36
|
+
requirements:
|
|
37
|
+
- - ">="
|
|
38
|
+
- !ruby/object:Gem::Version
|
|
39
|
+
version: '0'
|
|
40
|
+
description: 'See: https://gwil.garden/internet-time/'
|
|
41
|
+
email:
|
|
42
|
+
- packrat386@gmail.com
|
|
43
|
+
executables: []
|
|
44
|
+
extensions: []
|
|
45
|
+
extra_rdoc_files: []
|
|
46
|
+
files:
|
|
47
|
+
- README.md
|
|
48
|
+
- Rakefile
|
|
49
|
+
- lib/time/beat.rb
|
|
50
|
+
- lib/time/beat/version.rb
|
|
51
|
+
homepage: https://codeberg.org/packrat386/time-beat
|
|
52
|
+
licenses: []
|
|
53
|
+
metadata:
|
|
54
|
+
homepage_uri: https://codeberg.org/packrat386/time-beat
|
|
55
|
+
source_code_uri: https://codeberg.org/packrat386/time-beat
|
|
56
|
+
rdoc_options: []
|
|
57
|
+
require_paths:
|
|
58
|
+
- lib
|
|
59
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
60
|
+
requirements:
|
|
61
|
+
- - ">="
|
|
62
|
+
- !ruby/object:Gem::Version
|
|
63
|
+
version: 3.2.0
|
|
64
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
65
|
+
requirements:
|
|
66
|
+
- - ">="
|
|
67
|
+
- !ruby/object:Gem::Version
|
|
68
|
+
version: '0'
|
|
69
|
+
requirements: []
|
|
70
|
+
rubygems_version: 4.0.10
|
|
71
|
+
specification_version: 4
|
|
72
|
+
summary: Internet Time extension for time
|
|
73
|
+
test_files: []
|