ruby-stardate 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: bc33647a3d279829d6e5103a796a9e3ab388bcb1
4
- data.tar.gz: b55a1b8ba8118e47f82e7d279eee18972b09fb1d
2
+ SHA256:
3
+ metadata.gz: 28ea3896f93f62b8e850e52e69db1cd9507a52e907b0640b56fbc8e286346fbc
4
+ data.tar.gz: 0d427e2e54e0f94709525df29dcd0b489fcbe435a759c63a17135551520a0b89
5
5
  SHA512:
6
- metadata.gz: 6f5cbe88901c5c36b265c386cdfc7efb2100f1c639c8c0b0c396db4eb5edb44856013fdc3551bdaec2f65e3dc3619d558cebb48f097e719424ddcc19007558fc
7
- data.tar.gz: 5dba79d47ba365028a16e3facf25527d4094496e6a2d586371609a2f4239242b7ed8f84842d0e3a8ca2f57ab33552e4545057e69c0811249f19278aaeb13bc21
6
+ metadata.gz: 97df63528494c8c7e36baf9ef243258e1607cbfd83871140810d45f78409e62b5bbdbd06ab5a1db119425873bf2275064645cfaea0cd9a6639c22f12164a45df
7
+ data.tar.gz: 6ebe1de0ffbbe4fe71ed9fffbb40122e20f86ab0c93434cc9b0c5ce546ea21a7c5fc46c420bd236f4195797ad90b423356c424ebdcf7e9628e9c07ab8a6fb476
data/.rubocop.yml ADDED
@@ -0,0 +1,20 @@
1
+ Layout/LineLength:
2
+ Enabled: false
3
+
4
+ Naming/VariableNumber:
5
+ Enabled: false
6
+
7
+ Metrics/AbcSize:
8
+ Enabled: false
9
+
10
+ Style/Documentation:
11
+ Enabled: false
12
+
13
+ Style/FrozenStringLiteralComment:
14
+ Enabled: false
15
+
16
+ Style/RedundantSelf:
17
+ Enabled: false
18
+
19
+ Style/SpecialGlobalVars:
20
+ Enabled: false
data/README.md CHANGED
@@ -1,6 +1,7 @@
1
1
  # Stardate
2
2
 
3
- Calculates the Star Trek stardate and vice versa.
3
+ Calculates the Star Trek stardate and vice versa (Star Trek: The Next
4
+ Generation convention).
4
5
 
5
6
  ## Installation
6
7
 
@@ -22,13 +23,28 @@ Or install it yourself as:
22
23
  => true
23
24
 
24
25
  2.0.0-p247 :005 > t = Time.now + 400.years
25
- => 2413-11-26 18:35:34 +0100
26
+ => 2413-11-26 18:35:34 +0100
26
27
  2.0.0-p247 :006 > t.to_stardate
27
- => 90902.89247608284
28
+ => 90902.9
28
29
 
29
30
  2.0.0-p247 :007 > 1513.1.to_time
30
31
  => 2324-07-06 10:44:32 +0200
31
32
 
33
+ ### Change the base date
34
+
35
+ The default base date is `2323-1-1 = 0.0`. You can switch to the other standard
36
+ base date `2005-1-1 = 58000.0` with
37
+
38
+ ```ruby
39
+ Stardate.set_base_date_to_2005
40
+ ```
41
+
42
+ and switch back with
43
+
44
+ ```ruby
45
+ Stardate.set_base_date_to_2323
46
+ ```
47
+
32
48
  ## Contributing
33
49
 
34
50
  1. Fork it
data/Rakefile CHANGED
@@ -1 +1,8 @@
1
- require "bundler/gem_tasks"
1
+ require 'bundler/gem_tasks'
2
+ require 'rake/testtask'
3
+
4
+ Rake::TestTask.new do |test|
5
+ test.libs << 'test'
6
+ test.warning = true
7
+ test.test_files = FileList["test/test_#{ENV['T'] || '*'}.rb"]
8
+ end
@@ -1,3 +1,3 @@
1
1
  module Stardate
2
- VERSION = '0.0.1'
2
+ VERSION = '0.1.0'.freeze
3
3
  end
data/lib/stardate.rb CHANGED
@@ -2,8 +2,22 @@ require 'stardate/version'
2
2
  require 'active_support/time'
3
3
 
4
4
  module Stardate
5
- YEAR_O = 2323
6
- YEAR_DURATION = 365.2425 # Average value of a calendar year, considering the occurrence of leap years, in accordance with the inferred Stardates in Star Trek FAQ by Andrew Main
5
+ # Average value of a calendar year, considering the occurrence of leap
6
+ # years, in accordance with the inferred Stardates in Star Trek FAQ by
7
+ # Andrew Main
8
+ YEAR_DURATION = 365.2425
9
+
10
+ BASE_DATE = Struct.new(:year, :stardate).new(2323, 0.0)
11
+
12
+ def self.set_base_date_to_2323
13
+ BASE_DATE.year = 2323
14
+ BASE_DATE.stardate = 0.0
15
+ end
16
+
17
+ def self.set_base_date_to_2005
18
+ BASE_DATE.year = 2005
19
+ BASE_DATE.stardate = 58_000.0
20
+ end
7
21
 
8
22
  module STime
9
23
  def to_stardate
@@ -11,21 +25,21 @@ module Stardate
11
25
  t2 = self.beginning_of_day
12
26
  days = (t2 - t1) / 3600 / 24 # days passed since the beginning of the year
13
27
  seconds = self - t2 # seconds passed since the beginning of the day
14
- ((self.year - YEAR_O) + days / YEAR_DURATION + seconds / (YEAR_DURATION * 24 * 3600)) * 1000
28
+ (BASE_DATE.stardate + ((self.year - BASE_DATE.year) + days / YEAR_DURATION + seconds / (YEAR_DURATION * 24 * 3600)) * 1000).round(1)
15
29
  end
16
30
  end
17
31
 
18
32
  module SFloat
19
33
  def to_time
20
34
  y = 1000
21
- s = y / YEAR_DURATION / 24 / 3600
22
- year = (self / y).to_i
23
- seconds = ((self - (year * 1000)) / s).to_i
24
- d = Time.new(year + YEAR_O) + seconds.seconds
35
+ s = (y / YEAR_DURATION / 24 / 3600)
36
+ stardate = self.round(1) - BASE_DATE.stardate
37
+ year = (stardate / y).to_i
38
+ seconds = ((stardate - (year * 1000)) / s).to_i
39
+ Time.new(year + BASE_DATE.year) + seconds.seconds
25
40
  end
26
41
  end
27
-
28
42
  end
29
43
 
30
- Time.send(:include, Stardate::STime)
31
- Float.send(:include, Stardate::SFloat)
44
+ Time.include(Stardate::STime)
45
+ Float.include(Stardate::SFloat)
data/stardate.gemspec CHANGED
@@ -1,5 +1,4 @@
1
- # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
1
+ lib = File.expand_path('lib', __dir__)
3
2
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
3
  require 'stardate/version'
5
4
 
@@ -8,8 +7,8 @@ Gem::Specification.new do |spec|
8
7
  spec.version = Stardate::VERSION
9
8
  spec.authors = ['pioz']
10
9
  spec.email = ['enrico@megiston.it']
11
- spec.description = %q{Calculates the Star Trek stardate and vice versa}
12
- spec.summary = %q{Calculates the Star Trek stardate and vice versa.}
10
+ spec.description = 'Calculates the Star Trek stardate and vice versa'
11
+ spec.summary = 'Calculates the Star Trek stardate and vice versa.'
13
12
  spec.homepage = 'https://github.com/pioz/stardate'
14
13
  spec.license = 'MIT'
15
14
 
@@ -18,8 +17,13 @@ Gem::Specification.new do |spec|
18
17
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
18
  spec.require_paths = ['lib']
20
19
 
21
- spec.add_development_dependency 'bundler', '~> 1.3'
22
- spec.add_development_dependency 'rake'
20
+ spec.required_ruby_version = '>= 2.4.0'
21
+ spec.add_dependency 'activesupport', '>= 4'
23
22
 
24
- spec.add_dependency 'activesupport', '~> 4'
23
+ spec.add_development_dependency 'bundler'
24
+ spec.add_development_dependency 'byebug'
25
+ spec.add_development_dependency 'minitest'
26
+ spec.add_development_dependency 'rake'
27
+ spec.add_development_dependency 'rubocop'
28
+ spec.add_development_dependency 'rubocop-performance'
25
29
  end
@@ -0,0 +1,12 @@
1
+ # require 'simplecov'
2
+ # SimpleCov.start do
3
+ # add_filter 'lib/chess/gnuchess.rb'
4
+ # end
5
+ # if ENV['CODECOV'] == 'true'
6
+ # require 'codecov'
7
+ # SimpleCov.formatter = SimpleCov::Formatter::Codecov
8
+ # end
9
+
10
+ require 'stardate'
11
+ require 'minitest/autorun'
12
+ require 'byebug'
@@ -0,0 +1,35 @@
1
+ require 'test_helper'
2
+
3
+ class StardateTest < Minitest::Test
4
+ def test_to_stardate
5
+ Stardate.set_base_date_to_2323
6
+ time = Time.parse('2364-12-26 03:05:54')
7
+ assert_equal 41_986.0, time.to_stardate
8
+ end
9
+
10
+ def test_to_time
11
+ Stardate.set_base_date_to_2323
12
+ assert_equal Time.parse('2364-12-26 03:05:54'), 41_986.0.to_time
13
+ end
14
+
15
+ def test_to_stardate_base_date_2005
16
+ Stardate.set_base_date_to_2005
17
+ time = Time.parse('2364-12-26 03:05:54')
18
+ assert_equal 417_986.0, time.to_stardate
19
+ end
20
+
21
+ def test_to_time_base_date_2005
22
+ Stardate.set_base_date_to_2005
23
+ assert_equal Time.parse('2364-12-26 03:05:54'), 417_986.0.to_time
24
+ end
25
+
26
+ def test_to_stardate_to_time
27
+ time = Time.parse('2364-12-26 03:05:54')
28
+ assert_equal time, time.to_stardate.to_time
29
+ end
30
+
31
+ def test_to_time_to_stardate
32
+ s = 417_986.0
33
+ assert_equal s, s.to_time.to_stardate
34
+ end
35
+ end
metadata CHANGED
@@ -1,57 +1,113 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-stardate
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - pioz
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-11-26 00:00:00.000000000 Z
11
+ date: 2022-02-09 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '4'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '4'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: bundler
15
29
  requirement: !ruby/object:Gem::Requirement
16
30
  requirements:
17
- - - ~>
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: byebug
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
18
46
  - !ruby/object:Gem::Version
19
- version: '1.3'
47
+ version: '0'
20
48
  type: :development
21
49
  prerelease: false
22
50
  version_requirements: !ruby/object:Gem::Requirement
23
51
  requirements:
24
- - - ~>
52
+ - - ">="
25
53
  - !ruby/object:Gem::Version
26
- version: '1.3'
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: minitest
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
27
69
  - !ruby/object:Gem::Dependency
28
70
  name: rake
29
71
  requirement: !ruby/object:Gem::Requirement
30
72
  requirements:
31
- - - '>='
73
+ - - ">="
32
74
  - !ruby/object:Gem::Version
33
75
  version: '0'
34
76
  type: :development
35
77
  prerelease: false
36
78
  version_requirements: !ruby/object:Gem::Requirement
37
79
  requirements:
38
- - - '>='
80
+ - - ">="
39
81
  - !ruby/object:Gem::Version
40
82
  version: '0'
41
83
  - !ruby/object:Gem::Dependency
42
- name: activesupport
84
+ name: rubocop
43
85
  requirement: !ruby/object:Gem::Requirement
44
86
  requirements:
45
- - - ~>
87
+ - - ">="
46
88
  - !ruby/object:Gem::Version
47
- version: '4'
48
- type: :runtime
89
+ version: '0'
90
+ type: :development
49
91
  prerelease: false
50
92
  version_requirements: !ruby/object:Gem::Requirement
51
93
  requirements:
52
- - - ~>
94
+ - - ">="
53
95
  - !ruby/object:Gem::Version
54
- version: '4'
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rubocop-performance
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
55
111
  description: Calculates the Star Trek stardate and vice versa
56
112
  email:
57
113
  - enrico@megiston.it
@@ -59,7 +115,8 @@ executables: []
59
115
  extensions: []
60
116
  extra_rdoc_files: []
61
117
  files:
62
- - .gitignore
118
+ - ".gitignore"
119
+ - ".rubocop.yml"
63
120
  - Gemfile
64
121
  - LICENSE.txt
65
122
  - README.md
@@ -67,28 +124,31 @@ files:
67
124
  - lib/stardate.rb
68
125
  - lib/stardate/version.rb
69
126
  - stardate.gemspec
127
+ - test/test_helper.rb
128
+ - test/test_stardate.rb
70
129
  homepage: https://github.com/pioz/stardate
71
130
  licenses:
72
131
  - MIT
73
132
  metadata: {}
74
- post_install_message:
133
+ post_install_message:
75
134
  rdoc_options: []
76
135
  require_paths:
77
136
  - lib
78
137
  required_ruby_version: !ruby/object:Gem::Requirement
79
138
  requirements:
80
- - - '>='
139
+ - - ">="
81
140
  - !ruby/object:Gem::Version
82
- version: '0'
141
+ version: 2.4.0
83
142
  required_rubygems_version: !ruby/object:Gem::Requirement
84
143
  requirements:
85
- - - '>='
144
+ - - ">="
86
145
  - !ruby/object:Gem::Version
87
146
  version: '0'
88
147
  requirements: []
89
- rubyforge_project:
90
- rubygems_version: 2.1.10
91
- signing_key:
148
+ rubygems_version: 3.2.29
149
+ signing_key:
92
150
  specification_version: 4
93
151
  summary: Calculates the Star Trek stardate and vice versa.
94
- test_files: []
152
+ test_files:
153
+ - test/test_helper.rb
154
+ - test/test_stardate.rb