darian_calendar 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ OThlODFjMThlMDdmN2U4YzBmYTk1MGQxNjI0MzFmMzhkZmVjNWZhNA==
5
+ data.tar.gz: !binary |-
6
+ OWZmZDg5ZWE3MWE0YWQyMzQ0NWNkMWQ4Y2YwZjQ2YzM0MDVlYmZjNQ==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ ZTA3MjExNWMxYTEwYjgxZjkxYzU3MzIyNTUwYjMyYWY3YWFjY2RjNGM4MzQw
10
+ MTYwNzEzN2RjYjYzMTIyNGIyMjdhNzU5ZTgzOWU3ZGVmNTMzZjA3NTBmNmM4
11
+ ZDBiNWNiYWJjNGJiYjc4NzI0MDYxZjg5NjVhZDM1OGM1YWM5OGM=
12
+ data.tar.gz: !binary |-
13
+ ZTY3Y2I5NzBkZjBmOTYxYWE5ZjI5MGEyYmE3YTQzMmFlNjQwNTE1ZjBkMDM2
14
+ NTEwYjQ2NTQ4MjY3ZGJiN2FjNWMwNTJiYWQ2MjA3MGNlNjUyN2I2ZTIzNGY4
15
+ OTE3OWU5ZWNkNzJlNDg4YTEwOTIzMWRlNGE0YzYyOTIxMmE0MzI=
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ pkg
2
+ rdoc
3
+ doc
4
+ .yardoc
5
+ .DS_Store
6
+ .idea/*
7
+ *.sh
8
+ *.gem
9
+ Gemfile.lock
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --colour --format doc
data/.travis.yml ADDED
@@ -0,0 +1,8 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - 2.0.0
5
+ - 2.1.0
6
+ - jruby-19mode
7
+ - rbx-2.2.4
8
+ bundler_args: --without development
data/CHANGELOG.md ADDED
@@ -0,0 +1,7 @@
1
+ ## 0.1.0
2
+
3
+ - Working version of the darian calender converter
4
+
5
+ ## 0.0.1
6
+
7
+ - Initial release
data/Gemfile ADDED
@@ -0,0 +1,15 @@
1
+ source "https://rubygems.org"
2
+
3
+ group :development, :test do
4
+ gem 'rake'
5
+ end
6
+
7
+ group :test do
8
+ gem 'rspec'
9
+ end
10
+
11
+ platforms :rbx do
12
+ gem 'racc'
13
+ gem 'rubysl', '~> 2.0'
14
+ gem 'psych'
15
+ end
data/LICENSE.md ADDED
@@ -0,0 +1,155 @@
1
+ ## European Union Public Licence V. 1.1
2
+
3
+ _EUPL © the European Community 2007_
4
+
5
+ This European Union Public Licence (the "EUPL") applies to the Work or Software (as defined below) which is provided under the terms of this Licence. Any use of the Work, other than as authorised under this Licence is prohibited (to the extent such use is covered by a right of the copyright holder of the Work).
6
+
7
+ The Original Work is provided under the terms of this Licence when the Licensor (as defined below) has placed the following notice immediately following the copyright notice for the Original Work:
8
+
9
+ _Licensed under the EUPL V.1.1_
10
+
11
+ or has expressed by any other mean his willingness to license under the EUPL.
12
+
13
+
14
+ ### 1. Definitions
15
+
16
+ In this Licence, the following terms have the following meaning:
17
+
18
+ - _The Licence_: this Licence.
19
+ - _The Original Work_ or _the Software_: the software distributed and/or communicated by the Licensor under this Licence, available as Source Code and also as Executable Code as the case may be.
20
+ - _Derivative Works_: the works or software that could be created by the Licensee, based upon the Original Work or modifications thereof. This Licence does not define the extent of modification or dependence on the Original Work required in order to classify a work as a Derivative Work; this extent is determined by copyright law applicable in the country mentioned in Article 15.
21
+ - _The Work_: the Original Work and/or its Derivative Works.
22
+ - _The Source Code_: the human-readable form of the Work which is the most convenient for people to study and modify.
23
+ - _The Executable Code_: any code which has generally been compiled and which is meant to be interpreted by a computer as a program.
24
+ - _The Licensor_: the natural or legal person that distributes and/or communicates the Work under the Licence.
25
+ - _Contributor(s)_: any natural or legal person who modifies the Work under the Licence, or otherwise contributes to the creation of a Derivative Work.
26
+ - _The Licensee_ or _"You"_: any natural or legal person who makes any usage of the Software under the terms of the Licence.
27
+ - _Distribution_ and/or _Communication_: any act of selling, giving, lending, renting, distributing, communicating, transmitting, or otherwise making available, on-line or off-line, copies of the Work or providing access to its essential functionalities at the disposal of any other natural or legal person.
28
+
29
+
30
+ ### 2. Scope of the rights granted by the Licence
31
+
32
+ The Licensor hereby grants You a world-wide, royalty-free, non-exclusive, sub- licensable licence to do the following, for the duration of copyright vested in the Original Work:
33
+
34
+ - use the Work in any circumstance and for all usage,
35
+ - reproduce the W ork,
36
+ - modify the Original Work, and make Derivative Works based upon the Work,
37
+ - communicate to the public, including the right to make available or display the Work or copies thereof to the public and perform publicly, as the case may be, the Work,
38
+ - distribute the Work or copies thereof,
39
+ - lend and rent the Work or copies thereof,
40
+ - sub-license rights in the Work or copies thereof.
41
+
42
+ Those rights can be exercised on any media, supports and formats, whether now known or later invented, as far as the applicable law permits so.
43
+
44
+ In the countries where moral rights apply, the Licensor waives his right to exercise his moral right to the extent allowed by law in order to make effective the licence of the economic rights here above listed.
45
+
46
+ The Licensor grants to the Licensee royalty-free, non exclusive usage rights to any patents held by the Licensor, to the extent necessary to make use of the rights granted on the Work under this Licence.
47
+
48
+
49
+ ### 3. Communication of the Source Code
50
+
51
+ The Licensor may provide the Work either in its Source Code form, or as Executable Code. If the Work is provided as Executable Code, the Licensor provides in addition a machine-readable copy of the Source Code of the Work along with each copy of the Work that the Licensor distributes or indicates, in a notice following the copyright notice attached to the Work, a repository where the Source Code is easily and freely accessible for as long as the Licensor continues to distribute and/or communicate the W ork.
52
+
53
+
54
+ ### 4. Limitations on copyright
55
+
56
+ Nothing in this Licence is intended to deprive the Licensee of the benefits from any exception or limitation to the exclusive rights of the rights owners in the Original Work or Software, of the exhaustion of those rights or of other applicable limitations thereto.
57
+
58
+ ### 5. Obligations of the Licensee
59
+
60
+ The grant of the rights mentioned above is subject to some restrictions and obligations imposed on the Licensee. Those obligations are the following:
61
+
62
+ **Attribution right**: the Licensee shall keep intact all copyright, patent or trademarks notices and all notices that refer to the Licence and to the disclaimer of warranties. The Licensee must include a copy of such notices and a copy of the Licence with every copy of the Work he/she distributes and/or communicates. The Licensee must cause any Derivative Work to carry prominent notices stating that the Work has been modified and the date of modification.
63
+
64
+ **Copyleft clause**: If the Licensee distributes and/or communicates copies of the Original Works or Derivative Works based upon the Original Work, this Distribution and/or Communication will be done under the terms of this Licence or of a later version of this Licence unless the Original Work is expressly distributed only under this version of the Licence. The Licensee (becoming Licensor) cannot offer or impose any additional terms or conditions on the Work or Derivative Work that alter or restrict the terms of the Licence.
65
+
66
+ **Compatibility clause**: If the Licensee Distributes and/or Communicates Derivative Works or copies thereof based upon both the Original Work and another work licensed under a Compatible Licence, this Distribution and/or Communication can be done under the terms of this Compatible Licence. For the sake of this clause, "Compatible Licence" refers to the licences listed in the appendix attached to this Licence. Should the Licensee’s obligations under the Compatible Licence conflict with his/her obligations under this Licence, the obligations of the Compatible Licence shall prevail.
67
+
68
+ **Provision of Source Code**: When distributing and/or communicating copies of the Work, the Licensee will provide a machine-readable copy of the Source Code or indicate a repository where this Source will be easily and freely available for as long as the Licensee continues to distribute and/or communicate the Work.
69
+
70
+ **Legal Protection**: This Licence does not grant permission to use the trade names, trademarks, service marks, or names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the copyright notice.
71
+
72
+
73
+ ### 6. Chain of Authorship
74
+
75
+ The original Licensor warrants that the copyright in the Original Work granted hereunder is owned by him/her or licensed to him/her and that he/she has the power and authority to grant the Licence.
76
+
77
+ Each Contributor warrants that the copyright in the modifications he/she brings to the Work are owned by him/her or licensed to him/her and that he/she has the power and authority to grant the Licence.
78
+
79
+ Each time You accept the Licence, the original Licensor and subsequent Contributors grant You a licence to their contributions to the Work, under the terms of this Licence.
80
+
81
+
82
+ ### 7. Disclaimer of Warranty
83
+
84
+ The Work is a work in progress, which is continuously improved by numerous contributors. It is not a finished work and may therefore contain defects or "bugs" inherent to this type of software development.
85
+
86
+ For the above reason, the Work is provided under the Licence on an "as is" basis and without warranties of any kind concerning the Work, including without limitation merchantability, fitness for a particular purpose, absence of defects or errors, accuracy, non-infringement of intellectual property rights other than copyright as stated in Article 6 of this Licence.
87
+
88
+ This disclaimer of warranty is an essential part of the Licence and a condition for the grant of any rights to the Work.
89
+
90
+
91
+ ### 8. Disclaimer of Liability
92
+
93
+ Except in the cases of wilful misconduct or damages directly caused to natural persons, the Licensor will in no event be liable for any direct or indirect, material or moral, damages of any kind, arising out of the Licence or of the use of the Work, including without limitation, damages for loss of goodwill, work stoppage, computer failure or malfunction, loss of data or any commercial damage, even if the Licensor has been advised of the possibility of such damage. However, the Licensor will be liable under statutory product liability laws as far such laws apply to the Work.
94
+
95
+
96
+ ### 9. Additional agreements
97
+
98
+ While distributing the Original Work or Derivative Works, You may choose to conclude an additional agreement to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or services consistent with this Licence. However, in accepting such obligations, You may act only on your own behalf and on your sole responsibility, not on behalf of the original Licensor or any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against such Contributor by the fact You have accepted any such warranty or additional liability.
99
+
100
+
101
+ ### 10. Acceptance of the Licence
102
+
103
+ The provisions of this Licence can be accepted by clicking on an icon "I agree" placed under the bottom of a window displaying the text of this Licence or by affirming consent in any other similar way, in accordance with the rules of applicable law. Clicking on that icon indicates your clear and irrevocable acceptance of this Licence and all of its terms and conditions.
104
+
105
+ Similarly, you irrevocably accept this Licence and all of its terms and conditions by exercising any rights granted to You by Article 2 of this Licence, such as the use of the Work, the creation by You of a Derivative Work or the Distribution and/or Communication by You of the Work or copies thereof.
106
+
107
+
108
+ ### 11. Information to the public
109
+
110
+ In case of any Distribution and/or Communication of the Work by means of electronic communication by You (for example, by offering to download the Work from a remote location) the distribution channel or media (for example, a website) must at least provide to the public the information requested by the applicable law regarding the Licensor, the Licence and the way it may be accessible, concluded, stored and reproduced by the Licensee.
111
+
112
+
113
+ ### 12. Termination of the Licence
114
+
115
+ The Licence and the rights granted hereunder will terminate automatically upon any breach by the Licensee of the terms of the Licence.
116
+
117
+ Such a termination will not terminate the licences of any person who has received the Work from the Licensee under the Licence, provided such persons remain in full compliance with the Licence.
118
+
119
+
120
+ ### 13. Miscellaneous
121
+
122
+ Without prejudice of Article 9 above, the Licence represents the complete agreement between the Parties as to the Work licensed hereunder.
123
+
124
+ If any provision of the Licence is invalid or unenforceable under applicable law, this will not affect the validity or enforceability of the Licence as a whole. Such provision will be construed and/or reformed so as necessary to make it valid and enforceable.
125
+
126
+ The European Commission may publish other linguistic versions and/or new versions of this Licence, so far this is required and reasonable, without reducing the scope of the rights granted by the Licence. New versions of the Licence will be published with a unique version number.
127
+
128
+ All linguistic versions of this Licence, approved by the European Commission, have identical value. Parties can take advantage of the linguistic version of their choice.
129
+
130
+
131
+ ### 14. Jurisdiction
132
+
133
+ Any litigation resulting from the interpretation of this License, arising between the European Commission, as a Licensor, and any Licensee, will be subject to the jurisdiction of the Court of Justice of the European Communities, as laid down in article 238 of the Treaty establishing the European Community.
134
+
135
+ Any litigation arising between Parties, other than the European Commission, and resulting from the interpretation of this License, will be subject to the exclusive jurisdiction of the competent court where the Licensor resides or conducts its primary business.
136
+
137
+
138
+ ### 15. Applicable Law
139
+
140
+ This Licence shall be governed by the law of the European Union country where the Licensor resides or has his registered office.
141
+
142
+ This Licence shall be governed by the Belgian law if:
143
+
144
+ - a litigation arises between the European Commission, as a Licensor, and any Licensee;
145
+ - the Licensor, other than the European Commission, has no residence or registered office inside a European Union country.
146
+
147
+
148
+ ## Appendix
149
+
150
+ "Compatible Licences" according to article 5 EUPL are:
151
+
152
+ - _GNU General Public License (GNU GPL) v. 2 - Open Software License (OSL) v. 2.1, v. 3.0_
153
+ - _Common Public License v. 1.0_
154
+ - _Eclipse Public License v. 1.0_
155
+ - _Cecill v. 2.0_
data/README.md ADDED
@@ -0,0 +1,87 @@
1
+ # Darian Calendar
2
+
3
+ [![Build Status](https://travis-ci.org/marsec/darian_calendar.png)](https://travis-ci.org/marsec/darian_calendar)
4
+
5
+ _The [Darian calendar] is a proposed system of time-keeping designed to serve the needs of any possible future human settlers on the planet Mars.
6
+ It was created by aerospace engineer and political scientist Thomas Gangale in 1985 and named by him after his son Darius._ ([Wikipedia])
7
+
8
+ This Ruby library converts earth time to mars time and back again. You can choose between 5 variants of the Darian calendar system; _Martiana_, _Defrost_, _Areosynchronous_, _Hensel_ and _Aqua_.
9
+
10
+ It's based on the [JavaScript Converter] by Thomas Gangale.
11
+
12
+ [Wikipedia]: http://en.wikipedia.org/wiki/Darian_calendar
13
+ [Darian calendar]: http://en.wikipedia.org/wiki/Darian_calendar
14
+ [JavaScript Converter]: http://pweb.jps.net/~tgangale/mars/converter/calendar_clock.htm
15
+
16
+ ## Installation
17
+
18
+ ```ruby
19
+ gem 'darian_calendar', :git => 'git://github.com/marsec/darian_calendar.git'
20
+ ```
21
+
22
+ ## Usage
23
+
24
+ ```ruby
25
+ require 'darian_calendar'
26
+ ```
27
+
28
+ ```ruby
29
+ mars_time = DarianCalendar.now
30
+ mars_time = DarianCalendar.now(DarianCalendar::CalendarTypes::DEFROST)
31
+
32
+ mars_time = DarianCalendar::Time.now
33
+ mars_time = DarianCalendar::Time.now(DarianCalendar::CalendarTypes::AREOSYNCHRONOUS)
34
+
35
+ mars_time = DarianCalendar::Time.from_earth(Time.utc(2012, 10, 15, 16, 50, 0))
36
+ mars_time = DarianCalendar::Time.from_earth(Time.utc(2012, 10, 15, 16, 50, 0), DarianCalendar::CalendarTypes::AQUA)
37
+
38
+ mars_time = DarianCalendar::Time.parse_earth('2012-10-15 16:50:00 UTC')
39
+ mars_time = DarianCalendar::Time.parse_earth('2012-10-15 16:50:00 UTC', DarianCalendar::CalendarTypes::MARTIANA)
40
+ ```
41
+
42
+ ```ruby
43
+ mars_time.to_s #=> '214-14-26 20:10:02'
44
+
45
+ mars_time.year #=> 214
46
+ mars_time.month #=> 14
47
+ mars_time.sol #=> 26
48
+ mars_time.hour #=> 20
49
+ mars_time.min #=> 10
50
+ mars_time.sec #=> 2
51
+
52
+ mars_time.total_sols #=> 143466.84030197054
53
+ mars_time.season #=> 2
54
+ mars_time.sol_of_season #=> 53
55
+ mars_time.month_of_season #=> 1
56
+ mars_time.sol_of_year #=> 387
57
+ mars_time.week_sol #=> 5
58
+
59
+ mars_time.month_name #=> 'Sol Jovis'
60
+ mars_time.week_sol_name #=> 'Mithuna'
61
+ ```
62
+
63
+ ```ruby
64
+ mars_time = DarianCalendar::Time.from_earth(Time.utc(2012, 10, 15, 16, 50, 0))
65
+ mars_time.to_earth #=> 2012-10-15 16:50:00 UTC
66
+ ```
67
+
68
+ ```ruby
69
+ DarianCalendar::CalendarTypes::MARTIANA #=> Default
70
+ DarianCalendar::CalendarTypes::DEFROST
71
+ DarianCalendar::CalendarTypes::AREOSYNCHRONOUS
72
+ DarianCalendar::CalendarTypes::HENSEL
73
+ DarianCalendar::CalendarTypes::AQUA
74
+ ```
75
+
76
+ ## Testing
77
+
78
+ Unit tests are provided for all of Darian Calendar's methods:
79
+
80
+ ```bash
81
+ # From anywhere in the project directory:
82
+ bundle exec rspec
83
+ ```
84
+
85
+ ## License
86
+
87
+ This Darian Calendar Ruby Gem is released under the [European Union Public Licence V. 1.1](http://opensource.org/licenses/EUPL-1.1).
data/Rakefile ADDED
@@ -0,0 +1,17 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rake'
4
+
5
+ begin
6
+ require 'bundler/setup'
7
+ Bundler::GemHelper.install_tasks
8
+ rescue LoadError
9
+ puts 'although not required, bundler is recommened for running the tests'
10
+ end
11
+
12
+ task :default => :spec
13
+
14
+ require 'rspec/core/rake_task'
15
+ RSpec::Core::RakeTask.new do |t|
16
+ t.rspec_opts = ['--color', '--format doc']
17
+ end
@@ -0,0 +1,23 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ $LOAD_PATH.unshift File.expand_path('../lib', __FILE__)
4
+ require 'darian_calendar/version'
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = 'darian_calendar'
8
+ s.version = DarianCalendar::VERSION
9
+ s.date = Time.now.strftime('%Y-%m-%d')
10
+ s.platform = Gem::Platform::RUBY
11
+ s.summary = 'Converts earth time to mars time and back again. You can choose between 5 variants of the Darian calendar system.'
12
+ s.description = 'This Ruby library converts earth time to mars time and back again. You can choose between 5 variants of the Darian calendar system; Martiana, Defrost, Areosynchronous, Hensel and Aqua.'
13
+
14
+ s.authors = ['Christian Worreschk']
15
+ s.email = ['info@marsec.de']
16
+ s.homepage = 'http://github.com/marsec/darian_calendar'
17
+ s.licenses = ['EUPL-1.1']
18
+
19
+ s.require_paths = ['lib']
20
+ s.files = `git ls-files`.split("\n")
21
+ s.test_files = `git ls-files -- {spec}/*`.split("\n")
22
+ s.extra_rdoc_files = ['README.md', 'LICENSE.md', 'CHANGELOG.md']
23
+ end
@@ -0,0 +1,15 @@
1
+ # encoding: utf-8
2
+
3
+ require 'darian_calendar/time'
4
+
5
+ module DarianCalendar
6
+
7
+ class << self
8
+
9
+ def now
10
+ DarianCalendar::Time.now
11
+ end
12
+
13
+ end
14
+
15
+ end
@@ -0,0 +1,197 @@
1
+ # encoding: utf-8
2
+
3
+ module DarianCalendar
4
+
5
+ module CalendarTypes
6
+ MARTIANA = :martiana
7
+ DEFROST = :defrost
8
+ AREOSYNCHRONOUS = :areosynchronous
9
+ HENSEL = :hensel
10
+ AQUA = :aqua
11
+ end
12
+
13
+ class Time
14
+ include Comparable
15
+
16
+ #<editor-fold desc="Attributes">
17
+
18
+ attr_reader :year
19
+ attr_reader :month
20
+ attr_reader :sol
21
+
22
+ attr_reader :hour
23
+ attr_reader :min
24
+ attr_reader :sec
25
+
26
+ attr_reader :month_name
27
+ attr_reader :week_sol_name
28
+
29
+ attr_reader :total_sols
30
+ attr_reader :week_sol
31
+ attr_reader :season
32
+ attr_reader :sol_of_season
33
+ attr_reader :month_of_season
34
+ attr_reader :sol_of_year
35
+
36
+ attr_reader :calendar_type
37
+
38
+ alias :day :sol
39
+ alias :week_day :week_sol
40
+
41
+ #</editor-fold>
42
+
43
+ #<editor-fold desc="Constants">
44
+
45
+ MARS_TO_EARTH_DAYS = 1.027491251
46
+ EPOCH_OFFSET = 587744.77817
47
+ SECONDS_A_DAY = 86400.0
48
+ ROUND_UP_SECOND = 1/SECONDS_A_DAY;
49
+ E_DAYS_TIL_UNIX = 719527.0
50
+
51
+ SOL_MARTIANA = ['', 'Sol Solis', 'Sol Lunae', 'Sol Martis', 'Sol Mercurii', 'Sol Jovis', 'Sol Veneris', 'Sol Saturni']
52
+ SOL_DEFROST = ['', 'Axatisol', 'Benasol', 'Ciposol', 'Domesol', 'Erjasol', 'Fulisol', 'Gavisol']
53
+ SOL_AREOSYNCHRONOUS = ['', 'Heliosol', 'Phobosol', 'Deimosol', 'Terrasol', 'Venusol', 'Mercurisol', 'Jovisol']
54
+
55
+ MONTH_MARTIANA = ['', 'Sagittarius', 'Dhanus', 'Capricornus', 'Makara', 'Aquarius', 'Kumbha', 'Pisces', 'Mina', 'Aries', 'Mesha', 'Taurus', 'Rishabha', 'Gemini', 'Mithuna', 'Cancer', 'Karka', 'Leo', 'Simha', 'Virgo', 'Kanya', 'Libra', 'Tula', 'Scorpius', 'Vrishika']
56
+ MONTH_DEFROST = ['', 'Adir', 'Bora', 'Coan', 'Deti', 'Edal', 'Flo', 'Geor', 'Heliba', 'Idanon', 'Jowani', 'Kireal', 'Larno', 'Medior', 'Neturima', 'Ozulikan', 'Pasurabi', 'Rudiakel', 'Safundo', 'Tiunor', 'Ulasja', 'Vadeun', 'Wakumi', 'Xetual', 'Zungo']
57
+ MONTH_HENSEL = ['', 'Vernalis', 'Duvernalis', 'Trivernalis', 'Quadrivernalis', 'Pentavernalis', 'Hexavernalis', 'Aestas', 'Duestas', 'Triestas', 'Quadrestas', 'Pentestas', 'Hexestas', 'Autumnus', 'Duautumn', 'Triautumn', 'Quadrautumn', 'Pentautumn', 'Hexautumn', 'Unember', 'Duember', 'Triember', 'Quadrember', 'Pentember', 'Hexember']
58
+
59
+ #</editor-fold>
60
+
61
+ #<editor-fold desc="Class Methods">
62
+
63
+ def self.sols_from_earth_time(earth_time)
64
+ days = (earth_time.to_f / SECONDS_A_DAY) + E_DAYS_TIL_UNIX
65
+ sols = (days - EPOCH_OFFSET) / MARS_TO_EARTH_DAYS
66
+ return sols
67
+ end
68
+
69
+ def self.from_earth(earth_time, type=CalendarTypes::MARTIANA)
70
+ self.new(self.sols_from_earth_time(earth_time), type)
71
+ end
72
+
73
+ def self.parse_earth(string, type=CalendarTypes::MARTIANA)
74
+ self.from_earth(::Time.parse(string), type)
75
+ end
76
+
77
+ def self.now(type=CalendarTypes::MARTIANA)
78
+ self.from_earth(::Time.now, type)
79
+ end
80
+
81
+ #</editor-fold>
82
+
83
+ #<editor-fold desc="Instance Methods">
84
+
85
+ def <=>(another)
86
+ @total_sols <=> another.total_sols
87
+ end
88
+
89
+ def sols_in_year
90
+ self.leap? ? 669 : 668
91
+ end
92
+
93
+ def leap?
94
+ return true if (@year % 500) == 0
95
+ return false if (@year % 100) == 0
96
+ return true if (@year % 10) == 0
97
+ return false if (@year % 2) == 0
98
+ return true
99
+ end
100
+
101
+ def to_earth
102
+ earth_days = (@total_sols * MARS_TO_EARTH_DAYS) + EPOCH_OFFSET + ROUND_UP_SECOND
103
+ earth_seconds = ((earth_days - E_DAYS_TIL_UNIX) * SECONDS_A_DAY) - 1
104
+ ::Time.at(earth_seconds)
105
+ end
106
+
107
+ def to_s
108
+ sprintf('%d-%02d-%02d %02d:%02d:%02d', @year, @month, @sol, @hour, @min, @sec)
109
+ end
110
+
111
+ def initialize(sols=nil, type=CalendarTypes::MARTIANA)
112
+ @calendar_type = type.to_s.capitalize
113
+ @total_sols = sols.to_f != 0 ? sols.to_f : self.sols_from_earth_time(::Time.now)
114
+
115
+ sD = (@total_sols / 334296).floor
116
+ doD = (@total_sols - (sD * 334296)).floor
117
+
118
+ sC = 0
119
+ doC = doD
120
+ sC = ((doD - 1) / 66859).floor if doD != 0
121
+ doC -= ((sC * 66859) + 1) if sC != 0
122
+
123
+ sX = 0
124
+ doX = doC
125
+ if sC != 0 # century that does not begin with leap day
126
+ sX = ((doC + 1) / 6686).floor
127
+ doX -= ((sX * 6686) - 1) if sX != 0
128
+ else
129
+ sX = (doC / 6686).floor
130
+ doX -= (sX * 6686) if sX != 0
131
+ end
132
+
133
+ sII = 0
134
+ doII = doX
135
+ if (sC != 0) && (sX == 0) # decade that does not begin with leap day
136
+ sII = (doX / 1337).floor
137
+ doII -= (sII * 1337) if sII != 0
138
+ else # 1338, 1337, 1337, 1337 ...
139
+ sII = ((doX - 1) / 1337) if doX != 0
140
+ doII -= ((sII * 1337) + 1) if sII != 0
141
+ end
142
+
143
+ sI = 0
144
+ doI= doII
145
+ if (sII == 0) && ((sX != 0) || ((sX == 0) && (sC == 0)))
146
+ sI = (doII / 669).floor
147
+ doI -= 669 if sI != 0
148
+ else # 668, 669
149
+ sI = ((doII + 1) / 669).floor
150
+ doI -= 668 if sI != 0
151
+ end
152
+
153
+ @year = (500 * sD) + (100 * sC) + (10 * sX) + (2 * sII) + sI
154
+ @season = case true # 0-3
155
+ when (doI < 167) then 0
156
+ when (doI < 334) then 1
157
+ when (doI < 501) then 2
158
+ else 3
159
+ end
160
+
161
+ @sol_of_season = doI - 167 * @season # 0-167
162
+ @month_of_season = (@sol_of_season / 28).floor # 0-5
163
+ @sol_of_year = doI
164
+
165
+ @month = @month_of_season + (6 * @season) + 1 # 1-24
166
+ @sol = doI - (((@month - 1) * 28) - @season) + 1 # 1-28
167
+ @week_sol = ((@sol - 1) % 7) + 1 # 1-7
168
+
169
+ @week_sol_name = case type
170
+ when CalendarTypes::MARTIANA, CalendarTypes::HENSEL then SOL_MARTIANA[@week_sol]
171
+ when CalendarTypes::DEFROST then SOL_DEFROST[@week_sol]
172
+ when CalendarTypes::AREOSYNCHRONOUS then SOL_AREOSYNCHRONOUS[@week_sol]
173
+ when CalendarTypes::AQUA then @week_sol.to_s
174
+ else ''
175
+ end
176
+
177
+ @month_name = case type
178
+ when CalendarTypes::MARTIANA then MONTH_MARTIANA[@month]
179
+ when CalendarTypes::DEFROST, CalendarTypes::AREOSYNCHRONOUS then MONTH_DEFROST[@month]
180
+ when CalendarTypes::HENSEL then MONTH_HENSEL[@month]
181
+ when CalendarTypes::AQUA then @month.to_s
182
+ else ''
183
+ end
184
+
185
+ partial_sol = @total_sols - @total_sols.floor
186
+ hour = partial_sol* 24
187
+ min = (hour - hour.floor) * 60
188
+
189
+ @hour = hour.floor
190
+ @min = min.floor
191
+ @sec = ((min - min.floor) * 60).floor
192
+ end
193
+
194
+ #</editor-fold>
195
+
196
+ end
197
+ end
@@ -0,0 +1,3 @@
1
+ module DarianCalendar
2
+ VERSION = '0.1.0'
3
+ end
@@ -0,0 +1,18 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe DarianCalendar do
6
+
7
+ describe 'class methods' do
8
+
9
+ describe '#now' do
10
+ it 'returns current mars time' do
11
+ earth = Time.utc(2012, 10, 15, 16, 50, 0)
12
+ Time.should_receive(:now).and_return(earth)
13
+ DarianCalendar.now.should == DarianCalendar::Time.from_earth(earth)
14
+ end
15
+ end
16
+ end
17
+
18
+ end
@@ -0,0 +1,5 @@
1
+ # encoding: utf-8
2
+
3
+ require 'time'
4
+ require 'date'
5
+ require Pathname(__FILE__).dirname.join('../lib/darian_calendar').to_s
data/spec/time_spec.rb ADDED
@@ -0,0 +1,189 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe DarianCalendar::Time do
6
+
7
+ before do
8
+ @earth_time = Time.utc(2012, 10, 15, 16, 50, 0)
9
+ @mars_time = DarianCalendar::Time.from_earth(@earth_time)
10
+ end
11
+
12
+ describe 'attributes' do
13
+
14
+ it 'aliases day to sol and week day to week sol' do
15
+ @mars_time.day.should == @mars_time.sol
16
+ @mars_time.week_day.should == @mars_time.week_sol
17
+ end
18
+
19
+ end
20
+
21
+ describe 'initialize method' do
22
+ it 'converts earth time to mars time' do
23
+ @mars_time.year.should == 214
24
+ @mars_time.month.should == 14
25
+ @mars_time.sol.should == 26
26
+ @mars_time.hour.should == 20
27
+ @mars_time.min.should == 10
28
+ @mars_time.sec.should == 2
29
+
30
+ @mars_time.total_sols.should == 143466.84030197054
31
+ @mars_time.season.should == 2
32
+ @mars_time.sol_of_season.should == 53
33
+ @mars_time.month_of_season.should == 1
34
+ @mars_time.sol_of_year.should == 387
35
+ @mars_time.week_sol.should == 5
36
+ end
37
+ end
38
+
39
+ describe 'class methods' do
40
+
41
+ describe '.total_sols' do
42
+ it 'returns total sols from earth time' do
43
+ sols = DarianCalendar::Time.sols_from_earth_time(@earth_time)
44
+ sols.should == @mars_time.total_sols
45
+ end
46
+ end
47
+
48
+ describe '.parse_earth' do
49
+ it 'parses earth time and converts it to mars time' do
50
+ DarianCalendar::Time.parse_earth('2012-10-15 16:50:00 UTC').should == @mars_time
51
+ end
52
+ end
53
+
54
+ describe '.now' do
55
+ it 'returns current mars time' do
56
+ Time.should_receive(:now).and_return(@earth_time)
57
+ DarianCalendar.now.should == DarianCalendar::Time.from_earth(@earth_time)
58
+ end
59
+ end
60
+
61
+ end
62
+
63
+ describe 'instance methods' do
64
+
65
+ describe '#<=>' do
66
+ it 'compares mars time objects' do
67
+ same_time = DarianCalendar::Time.from_earth(Time.utc(2012, 10, 15, 16, 50, 0))
68
+ past_time = DarianCalendar::Time.from_earth(Time.utc(2012, 10, 15, 16, 49, 59))
69
+ future_time = DarianCalendar::Time.from_earth(Time.utc(2012, 10, 15, 16, 50, 1))
70
+
71
+ @mars_time.should == same_time
72
+ @mars_time.should > past_time
73
+ @mars_time.should < future_time
74
+
75
+ @mars_time.should_not < past_time
76
+ @mars_time.should_not > future_time
77
+ end
78
+ end
79
+
80
+ describe '#sols_in_year' do
81
+ it 'returns the count of sols in a martian year' do
82
+ leap_mars_time = DarianCalendar::Time.from_earth(Time.utc(2013, 10, 15, 16, 50, 0))
83
+ leap_mars_time.sols_in_year.should == 669
84
+ @mars_time.sols_in_year.should == 668
85
+ end
86
+ end
87
+
88
+ describe '#leap?' do
89
+ it 'returns if year is a leap year' do
90
+ leap_mars_time = DarianCalendar::Time.from_earth(Time.utc(2013, 10, 15, 16, 50, 0))
91
+ leap_mars_time.leap?.should == true
92
+ @mars_time.leap?.should == false
93
+ end
94
+ end
95
+
96
+ describe '#to_earth' do
97
+ it 'converts mars time to earth time' do
98
+ @earth_time == @mars_time.to_earth
99
+ end
100
+ end
101
+
102
+ describe '#to_s' do
103
+ it 'converts mars time to string' do
104
+ @mars_time.to_s.should == '214-14-26 20:10:02'
105
+ end
106
+ end
107
+
108
+ describe '#week_sol_name' do
109
+ context 'calendar type is not set' do
110
+ it 'returns "Sol Jovis"' do
111
+ @mars_time.week_sol_name.should == 'Sol Jovis'
112
+ end
113
+ end
114
+ context 'calendar type is "Martina"' do
115
+ it 'returns "Sol Jovis"' do
116
+ mars_time = DarianCalendar::Time.from_earth(@earth_time, DarianCalendar::CalendarTypes::MARTIANA)
117
+ mars_time.week_sol_name.should == 'Sol Jovis'
118
+ end
119
+ end
120
+ context 'calendar type is "Defrost"' do
121
+ it 'returns "Erjasol"' do
122
+ mars_time = DarianCalendar::Time.from_earth(@earth_time, DarianCalendar::CalendarTypes::DEFROST)
123
+ mars_time.week_sol_name.should == 'Erjasol'
124
+ end
125
+ end
126
+ context 'calendar type is "Areosynchronous"' do
127
+ it 'returns "Venusol"' do
128
+ mars_time = DarianCalendar::Time.from_earth(@earth_time, DarianCalendar::CalendarTypes::AREOSYNCHRONOUS)
129
+ mars_time.week_sol_name.should == 'Venusol'
130
+ end
131
+ end
132
+ context 'calendar type is "Hensel"' do
133
+ it 'returns "Sol Jovis"' do
134
+ mars_time = DarianCalendar::Time.from_earth(@earth_time, DarianCalendar::CalendarTypes::HENSEL)
135
+ mars_time.week_sol_name.should == 'Sol Jovis'
136
+ end
137
+ end
138
+ context 'calendar type is "Aqua"' do
139
+ it 'returns "5"' do
140
+ mars_time = DarianCalendar::Time.from_earth(@earth_time, DarianCalendar::CalendarTypes::AQUA)
141
+ mars_time.week_sol_name.should == '5'
142
+ end
143
+ end
144
+ end
145
+
146
+ describe '#month_name' do
147
+ context 'calendar type is not set' do
148
+ it 'returns "Mithuna"' do
149
+ @mars_time.month_name.should == 'Mithuna'
150
+ end
151
+ end
152
+ context 'calendar type is "Martina"' do
153
+ it 'returns "Mithuna"' do
154
+ mars_time = DarianCalendar::Time.from_earth(@earth_time, DarianCalendar::CalendarTypes::MARTIANA)
155
+ mars_time.month_name.should == 'Mithuna'
156
+ end
157
+ end
158
+ context 'calendar type is "Defrost"' do
159
+ it 'returns "Neturima"' do
160
+ mars_time = DarianCalendar::Time.from_earth(@earth_time, DarianCalendar::CalendarTypes::DEFROST)
161
+ mars_time.month_name.should == 'Neturima'
162
+ end
163
+ end
164
+ context 'calendar type is "Areosynchronous"' do
165
+ it 'returns "Neturima"' do
166
+ mars_time = DarianCalendar::Time.from_earth(@earth_time, DarianCalendar::CalendarTypes::AREOSYNCHRONOUS)
167
+ mars_time.month_name.should == 'Neturima'
168
+ end
169
+ end
170
+ context 'calendar type is "Hensel"' do
171
+ it 'returns "Duautumn"' do
172
+ mars_time = DarianCalendar::Time.from_earth(@earth_time, DarianCalendar::CalendarTypes::HENSEL)
173
+ mars_time.month_name.should == 'Duautumn'
174
+ end
175
+ end
176
+ context 'calendar type is "Aqua"' do
177
+ it 'returns "14"' do
178
+ mars_time = DarianCalendar::Time.from_earth(@earth_time, DarianCalendar::CalendarTypes::AQUA)
179
+ mars_time.month_name.should == '14'
180
+ end
181
+ end
182
+ end
183
+
184
+ end
185
+
186
+
187
+
188
+ end
189
+
metadata ADDED
@@ -0,0 +1,65 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: darian_calendar
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Christian Worreschk
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-02-07 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: This Ruby library converts earth time to mars time and back again. You
14
+ can choose between 5 variants of the Darian calendar system; Martiana, Defrost,
15
+ Areosynchronous, Hensel and Aqua.
16
+ email:
17
+ - info@marsec.de
18
+ executables: []
19
+ extensions: []
20
+ extra_rdoc_files:
21
+ - README.md
22
+ - LICENSE.md
23
+ - CHANGELOG.md
24
+ files:
25
+ - .gitignore
26
+ - .rspec
27
+ - .travis.yml
28
+ - CHANGELOG.md
29
+ - Gemfile
30
+ - LICENSE.md
31
+ - README.md
32
+ - Rakefile
33
+ - darian_calendar.gemspec
34
+ - lib/darian_calendar.rb
35
+ - lib/darian_calendar/time.rb
36
+ - lib/darian_calendar/version.rb
37
+ - spec/darian_calendar_spec.rb
38
+ - spec/spec_helper.rb
39
+ - spec/time_spec.rb
40
+ homepage: http://github.com/marsec/darian_calendar
41
+ licenses:
42
+ - EUPL-1.1
43
+ metadata: {}
44
+ post_install_message:
45
+ rdoc_options: []
46
+ require_paths:
47
+ - lib
48
+ required_ruby_version: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ! '>='
51
+ - !ruby/object:Gem::Version
52
+ version: '0'
53
+ required_rubygems_version: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ! '>='
56
+ - !ruby/object:Gem::Version
57
+ version: '0'
58
+ requirements: []
59
+ rubyforge_project:
60
+ rubygems_version: 2.2.2
61
+ signing_key:
62
+ specification_version: 4
63
+ summary: Converts earth time to mars time and back again. You can choose between 5
64
+ variants of the Darian calendar system.
65
+ test_files: []