wtf 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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 69a80abf1e7dbe38e1f042d55901b26124b9086a9955e87e6326ea1636272b68
4
+ data.tar.gz: 6b1a7264209e49aa64185591b80bab0e615653a497414833692ca6b676dba2dc
5
+ SHA512:
6
+ metadata.gz: 2968c1f4097475f4e5953a62cab2ba7c5d91ce44ebf5afc2bb6cd72d708f6ea9734ffa1861c6252dec1776c806157545be454584aa04179e7616bc3e2c7ee08d
7
+ data.tar.gz: e6ea97c72ab9021def291022db51cbf1405e6abe0df290b3fbc44b4d7c405a5b2f4e35a61fbf9d3949214d11def221a8796755fcfe55c27dce3b8a4f9ff1c279
checksums.yaml.gz.sig ADDED
Binary file
@@ -0,0 +1,55 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Released under the MIT License.
4
+ # Copyright, 2024, by Samuel Williams.
5
+
6
+ module WTF
7
+ def self.is_it_doing?(object)
8
+ log_all_the_things = Module.new
9
+ log_all_the_things.include(IsItDoing)
10
+
11
+ object.methods.each do |method|
12
+ next if method.to_s.start_with?('__')
13
+
14
+ log_all_the_things.define_method(method) do |*arguments, **options, &block|
15
+ __log__(__method__, arguments, options, block)
16
+
17
+ super(*arguments, **options, &block)
18
+ end
19
+ end
20
+
21
+ object.singleton_class.prepend(log_all_the_things)
22
+
23
+ return object
24
+ end
25
+
26
+ module IsItDoing
27
+ alias __class__ class
28
+
29
+ def __log__(method, arguments, options, block)
30
+ buffer = String.new
31
+ buffer << __class__.name << '#' << method.to_s << '('
32
+ first = true
33
+
34
+ if arguments.any?
35
+ buffer << arguments.inspect[1...-1]
36
+ first = false
37
+ end
38
+
39
+ if options.any?
40
+ buffer << ', ' unless first
41
+ buffer << options.inspect[1...-1]
42
+ first = false
43
+ end
44
+
45
+ if block
46
+ buffer << ', ' unless first
47
+ buffer << '&' << block.inspect
48
+ end
49
+
50
+ buffer << ')'
51
+
52
+ $stderr.puts(buffer)
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Released under the MIT License.
4
+ # Copyright, 2024, by Samuel Williams.
5
+
6
+ module WTF
7
+ VERSION = "0.1.0"
8
+ end
data/lib/wtf.rb CHANGED
@@ -1,288 +1,7 @@
1
- require 'date'
1
+ # frozen_string_literal: true
2
2
 
3
- module WTF
4
- class Date
5
-
6
- # creates a new WTF::Date object. The argument can be a string representing the
7
- # date and/or time in World Time Format, or it can be a Time object. If the
8
- # argument is missing, Time.now is assumed.
9
- #
10
- # Examples:
11
- #
12
- # WTF::Date.new(":NB") #=> returns a new WTF::Date object for the WTF time :NB
13
- # WTF::Date.new(":RJA") #=> returns a new WTF::Date object for the WTF date :RJA
14
- # WTF::Date.new("MM:BRT") #=> returns a new WTF::Date object for the WTF datetime MM:BRT
15
- # WTF::Date.new #=> returns a new WTF::Date object corresponding to right now
16
- # WTF::Date.new(Time.utc(2010, 5, 6)) #=> returns a new WTF::Date object for the given Time
17
- #
18
- # If the argument is in World Time Format, it must can contain a date part,
19
- # a time part, and a colon to separate them. Here are some examples of valid formats:
20
- #
21
- # - "FJKRM:BROMQ" -- This is a fully specified World Time Format date and
22
- # time. The first part is the date part and the second part is the time
23
- # part. The date part cannot be longer than five characters. The time
24
- # part can be longer than five characters, but any characters after
25
- # the fifth character are ignored when calculating.
26
- # - ":BROMQ" -- You can leave out the date part. Today is assumed.
27
- # - "FJKRM:" -- You can leave out the time part. The beginning of the
28
- # Julian day is assumed (which is noon).
29
- # - "BROMQ" -- If you leave out the colon, it is assumed that you are
30
- # giving the time, not the date.
31
- # - "RM:BROMQ" -- You can leave out some of the digits for the date. If
32
- # you do, the remaining digits will be filled in according to today's
33
- # date. If today's date is FMBAZ, then "RM:BROMQ" becomes
34
- # "FMBRM:BROMQ".
35
- # - ":BR" -- You don't have to specify all five of the time digits.
36
- # - "A:B" -- This is a valid format.
37
- #
38
- # Also note:
39
- #
40
- # - The date conversion does not work before the Gregorian calendar change
41
- # that happened in October 1582.
42
- # - Since the date part is limited to five characters, there is an upper
43
- # bound for how far into the future you can do a date conversion.
44
- # - The time part is limited to five characters and therefore the
45
- # time precision is limited to about 10 milliseconds.
46
- # - Leap seconds were not taken into account.
47
- #
48
- def initialize(time = nil)
49
- if time
50
- if time.is_a? String
51
- @time = convert_from_wtf(time)
52
- elsif time.is_a? Time
53
- @time = time
54
- else
55
- raise ArgumentError.new("Argument must be a String or a Time.")
56
- end
57
- else
58
- @time = ::Time.now
59
- end
60
- @wtf = convert_to_wtf(@time)
61
- end
62
-
63
- # now is a synonym for WTF::Date.new. It returns a WTF::Date object initialized with
64
- # the current date and time.
65
- #
66
- def self.now
67
- self.new
68
- end
3
+ # Released under the MIT License.
4
+ # Copyright, 2024, by Samuel Williams.
69
5
 
70
- # convert is a convenience method to make it easier to convert between WTF
71
- # times and standard times.
72
- #
73
- # Examples:
74
- #
75
- # WTF::Date.convert("FIWIT:NAAAA") #=> same as WTF::Date.new("FIWIT:NAAAA").as_utc
76
- # WTF::Date.convert(time) #=> same as WTF::Date.new(time).as_wtf
77
- #
78
- def self.convert(arg)
79
- return nil if arg.nil?
80
- return self.new(arg).as_utc if arg.is_a?(String)
81
- return self.new(arg).as_wtf if arg.is_a?(Time)
82
- raise ArgumentError.new("Argument must be a String or a Time.")
83
- end
84
-
85
- # returns a Time object representing the WTF::Date's date and time in UTC.
86
- #
87
- # Examples:
88
- #
89
- # standard_time = WTF::Date.new("FIWIT:NAAAA").as_utc
90
- # standard_time = WTF::Date.new(":BJR").as_utc
91
- # standard_time = WTF::Date.new("XQ:ARM").as_utc
92
- #
93
- def as_utc
94
- @time
95
- end
96
-
97
- # returns a string representing the date and time in World Time Format.
98
- #
99
- # Example:
100
- #
101
- # wtf_date = WTF::Date.new(Time.utc(2002, 7, 10, 13, 55, 1, 777000))
102
- # wtf_date.as_wtf #=> "FJNXQ:CCAAA"
103
- #
104
- def as_wtf
105
- @wtf
106
- end
107
-
108
- # returns just the World Time Format date.
109
- #
110
- # Example:
111
- #
112
- # wtf_date = WTF::Date.new(Time.utc(2002, 7, 10, 13, 55, 1, 777000))
113
- # wtf_date.date_part #=> "FJNXQ"
114
- #
115
- def date_part
116
- @wtf =~ /^([A-Z]{0,5}):([A-Z]*)$/
117
- $1
118
- end
119
-
120
- # returns just the World Time Format time.
121
- #
122
- # Example:
123
- #
124
- # wtf_date = WTF::Date.new(Time.utc(2002, 7, 10, 13, 55, 1, 777000))
125
- # wtf_date.time_part #=> "CCAAA"
126
- #
127
- def time_part
128
- @wtf =~ /^([A-Z]{0,5}):([A-Z]*)$/
129
- $2
130
- end
131
-
132
- #--------------------#
133
- # PRIVATE METHODS #
134
- #++
135
-
136
- private
137
-
138
- SECONDS_IN_A_DAY = 86400
139
- MILLIS_IN_A_DAY = SECONDS_IN_A_DAY * 1000 # millis means milliseconds
140
-
141
- def convert_from_wtf(wtf)
142
-
143
- raise ArgumentError.new("Argument is empty.") if wtf.nil? || wtf.empty?
144
-
145
- # If no colon is given, we assume we have a time, not a date.
146
- if !wtf.include?(":")
147
- wtf = ":" + wtf
148
- end
149
-
150
- if wtf !~ /^([A-Z]{0,5}):([A-Z]*)$/
151
- raise ArgumentError.new("Time format error")
152
- end
153
- wtf_date = $1
154
- wtf_time = $2
155
-
156
- # we need to fill in ambiguous dates. If today is FJSTR: and the given
157
- # date is BM:, we fill in the blanks according to today's date
158
- # like so: FJSBM:
159
- if wtf_date.length < 5
160
- reference_date = self.class.now.date_part
161
- wtf_date = reference_date[0, 5-wtf_date.length] + wtf_date
162
- end
163
-
164
- # we don't care about anything more precise than 5 time digits
165
- if wtf_time.length > 5
166
- wtf_time = wtf_time[0, 5]
167
- end
168
-
169
- julian_date = 0
170
- # compute integer part of Julian Date
171
- for i in (0..4) do
172
- julian_date += (wtf_date[i]-65) * (26**(4-i))
173
- end
174
- # compute fractional part of Julian Date
175
- fractional = 0
176
- for i in (0..(wtf_time.length-1)) do
177
- fractional += (wtf_time[i]-65) / (26**(i+1)).to_f
178
- end
179
-
180
- # adjust for the astronomical Julian day, which starts at noon
181
- if fractional >= 0.5
182
- fractional -= 0.5
183
- julian_date += 1
184
- else
185
- fractional += 0.5
186
- end
187
-
188
- date = ::Date.jd(julian_date+fractional)
189
-
190
- # Normally I love Ruby and how it gets out of my way, but this is
191
- # absolutely ridiculous. I expect to be able to create a Date object,
192
- # initialize it with the Julian Day, then simply call to_time.
193
- # Why Ruby doesn't provide a to_time method, I don't know. So I'm resorting
194
- # to calling private (!) methods on the Date class. Shame on Ruby
195
- # and shame on me! :)
196
- fraction_of_seconds = date.send(:sec_fraction) * SECONDS_IN_A_DAY
197
- microseconds = fraction_of_seconds * 1000000
198
- utc_time = ::Time.utc(date.year,
199
- date.month,
200
- date.day,
201
- date.send(:hour),
202
- date.send(:min),
203
- date.send(:sec),
204
- microseconds)
205
-
206
- utc_time.getlocal
207
-
208
- end
209
-
210
- def convert_to_wtf(time)
211
- utc = time.utc
212
- date = ::Date.civil(utc.year, utc.month, utc.day)
213
- julian_day = date.jd.to_i
214
- # adjust for the astronomical Julian day, which starts at noon
215
- if utc.hour >= 12
216
- hour = utc.hour - 12
217
- else
218
- hour = utc.hour + 12
219
- julian_day -= 1
220
- end
221
- fractional = hour * 3600 + utc.min * 60 + utc.sec + (utc.usec / 1000000.0)
222
- date_part = self.class.send(:decimal_to_alphabase, julian_day)
223
- time_part = self.class.send(:time_to_wtf, fractional*1000)
224
- date_part + ':' + time_part
225
- end
226
-
227
- # Given a number in base 10, return a number in alphabase. Note that
228
- # alphabase is different than base 26. Base 26 uses digits within the range
229
- # 0-9,a-p. Alphabase is also based on a radix of 26, but uses digits within
230
- # the range A-Z.
231
- #
232
- # To simplify the algorithm, this function does not accept real numbers as
233
- # input, only integers.
234
- #
235
- def self.decimal_to_alphabase(decimal)
236
- if (decimal.floor != decimal)
237
- raise ArgumentError.new("Floats are not supported.")
238
- end
239
- alphabase = ""
240
- base26 = decimal.to_s(26)
241
- for i in (0..(base26.length-1))
242
- c = base26[i]
243
- if (c == 45) # hyphen for negative numbers
244
- alphabase += "-"
245
- elsif ((c >= 97) && (c <= 112)) # lower case a-p -> K-Z
246
- alphabase += (c-22).chr
247
- elsif ((c >= 48) && (c <= 57)) # number 0-9 -> A-J
248
- alphabase += (c+17).chr
249
- else
250
- raise "Unexpected character."
251
- end
252
- end
253
- alphabase
254
- end
255
- private_class_method :decimal_to_alphabase
256
-
257
- # Given an integer representing the number of milliseconds into the Julian
258
- # day, return a five-character string representing the time in World Time
259
- # Format.
260
- #
261
- def self.time_to_wtf(millis_into_the_day)
262
- if (millis_into_the_day < 0)
263
- raise ArgumentError.new("Negative values are not supported.")
264
- end
265
- if (millis_into_the_day >= MILLIS_IN_A_DAY)
266
- message = "Value (#{millis_into_the_day}) must be smaller than"
267
- message << " the number of milliseconds in a day (#{MILLIS_IN_A_DAY})."
268
- raise ArgumentError.new(message)
269
- end
270
- result = ""
271
- # For the first loop iteration, the unit represents the number of
272
- # milliseconds in an entire day. Then it represents the number of
273
- # milliseconds in an alphabetic hour, then in an alphabetic minute, all
274
- # the way down to the number of milliseconds in an alphabetic subsubsecond.
275
- unit = MILLIS_IN_A_DAY
276
- remainder = millis_into_the_day # milliseconds left to process
277
- 5.times do
278
- unit /= 26.0
279
- num_units = (remainder.floor / unit).to_i
280
- remainder -= (num_units * unit)
281
- result += (num_units.to_i+65).chr
282
- end
283
- result
284
- end
285
- private_class_method :time_to_wtf
286
-
287
- end
288
- end
6
+ require_relative 'wtf/version'
7
+ require_relative 'wtf/is_it_doing'
@@ -1,6 +1,6 @@
1
- The MIT License
1
+ # MIT License
2
2
 
3
- Copyright (c) 2009 Wyatt M. Greene
3
+ Copyright, 2024, by Samuel Williams.
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
@@ -9,13 +9,13 @@ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
9
  copies of the Software, and to permit persons to whom the Software is
10
10
  furnished to do so, subject to the following conditions:
11
11
 
12
- The above copyright notice and this permission notice shall be included in
13
- all copies or substantial portions of the Software.
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
14
 
15
15
  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
16
  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
17
  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
18
  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
19
  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
- THE SOFTWARE.
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/readme.md ADDED
@@ -0,0 +1,35 @@
1
+ # WTF
2
+
3
+ This gem will help you understand WTF your program is doing.
4
+
5
+ [![Development Status](https://github.com/ioquatix/wtf/workflows/Test/badge.svg)](https://github.com/ioquatix/wtf/actions?workflow=Test)
6
+
7
+ ## Usage
8
+
9
+ ```ruby
10
+ require 'wtf'
11
+
12
+ string = "Hello World"
13
+
14
+ WTF.is_it_doing?(string)
15
+
16
+ string.upcase!
17
+ ```
18
+
19
+ ## Contributing
20
+
21
+ We welcome contributions to this project.
22
+
23
+ 1. Fork it.
24
+ 2. Create your feature branch (`git checkout -b my-new-feature`).
25
+ 3. Commit your changes (`git commit -am 'Add some feature'`).
26
+ 4. Push to the branch (`git push origin my-new-feature`).
27
+ 5. Create new Pull Request.
28
+
29
+ ### Developer Certificate of Origin
30
+
31
+ This project uses the [Developer Certificate of Origin](https://developercertificate.org/). All contributors to this project must agree to this document to have their contributions accepted.
32
+
33
+ ### Contributor Covenant
34
+
35
+ This project is governed by the [Contributor Covenant](https://www.contributor-covenant.org/). All contributors and participants agree to abide by its terms.
data.tar.gz.sig ADDED
Binary file
metadata CHANGED
@@ -1,63 +1,79 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: wtf
3
- version: !ruby/object:Gem::Version
4
- version: 0.0.1
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
5
  platform: ruby
6
- authors:
7
- - Wyatt Greene
8
- autorequire:
6
+ authors:
7
+ - Samuel Williams
8
+ autorequire:
9
9
  bindir: bin
10
- cert_chain: []
11
-
12
- date: 2009-11-29 00:00:00 -05:00
13
- default_executable:
10
+ cert_chain:
11
+ - |
12
+ -----BEGIN CERTIFICATE-----
13
+ MIIE2DCCA0CgAwIBAgIBATANBgkqhkiG9w0BAQsFADBhMRgwFgYDVQQDDA9zYW11
14
+ ZWwud2lsbGlhbXMxHTAbBgoJkiaJk/IsZAEZFg1vcmlvbnRyYW5zZmVyMRIwEAYK
15
+ CZImiZPyLGQBGRYCY28xEjAQBgoJkiaJk/IsZAEZFgJuejAeFw0yMjA4MDYwNDUz
16
+ MjRaFw0zMjA4MDMwNDUzMjRaMGExGDAWBgNVBAMMD3NhbXVlbC53aWxsaWFtczEd
17
+ MBsGCgmSJomT8ixkARkWDW9yaW9udHJhbnNmZXIxEjAQBgoJkiaJk/IsZAEZFgJj
18
+ bzESMBAGCgmSJomT8ixkARkWAm56MIIBojANBgkqhkiG9w0BAQEFAAOCAY8AMIIB
19
+ igKCAYEAomvSopQXQ24+9DBB6I6jxRI2auu3VVb4nOjmmHq7XWM4u3HL+pni63X2
20
+ 9qZdoq9xt7H+RPbwL28LDpDNflYQXoOhoVhQ37Pjn9YDjl8/4/9xa9+NUpl9XDIW
21
+ sGkaOY0eqsQm1pEWkHJr3zn/fxoKPZPfaJOglovdxf7dgsHz67Xgd/ka+Wo1YqoE
22
+ e5AUKRwUuvaUaumAKgPH+4E4oiLXI4T1Ff5Q7xxv6yXvHuYtlMHhYfgNn8iiW8WN
23
+ XibYXPNP7NtieSQqwR/xM6IRSoyXKuS+ZNGDPUUGk8RoiV/xvVN4LrVm9upSc0ss
24
+ RZ6qwOQmXCo/lLcDUxJAgG95cPw//sI00tZan75VgsGzSWAOdjQpFM0l4dxvKwHn
25
+ tUeT3ZsAgt0JnGqNm2Bkz81kG4A2hSyFZTFA8vZGhp+hz+8Q573tAR89y9YJBdYM
26
+ zp0FM4zwMNEUwgfRzv1tEVVUEXmoFCyhzonUUw4nE4CFu/sE3ffhjKcXcY//qiSW
27
+ xm4erY3XAgMBAAGjgZowgZcwCQYDVR0TBAIwADALBgNVHQ8EBAMCBLAwHQYDVR0O
28
+ BBYEFO9t7XWuFf2SKLmuijgqR4sGDlRsMC4GA1UdEQQnMCWBI3NhbXVlbC53aWxs
29
+ aWFtc0BvcmlvbnRyYW5zZmVyLmNvLm56MC4GA1UdEgQnMCWBI3NhbXVlbC53aWxs
30
+ aWFtc0BvcmlvbnRyYW5zZmVyLmNvLm56MA0GCSqGSIb3DQEBCwUAA4IBgQB5sxkE
31
+ cBsSYwK6fYpM+hA5B5yZY2+L0Z+27jF1pWGgbhPH8/FjjBLVn+VFok3CDpRqwXCl
32
+ xCO40JEkKdznNy2avOMra6PFiQyOE74kCtv7P+Fdc+FhgqI5lMon6tt9rNeXmnW/
33
+ c1NaMRdxy999hmRGzUSFjozcCwxpy/LwabxtdXwXgSay4mQ32EDjqR1TixS1+smp
34
+ 8C/NCWgpIfzpHGJsjvmH2wAfKtTTqB9CVKLCWEnCHyCaRVuKkrKjqhYCdmMBqCws
35
+ JkxfQWC+jBVeG9ZtPhQgZpfhvh+6hMhraUYRQ6XGyvBqEUe+yo6DKIT3MtGE2+CP
36
+ eX9i9ZWBydWb8/rvmwmX2kkcBbX0hZS1rcR593hGc61JR6lvkGYQ2MYskBveyaxt
37
+ Q2K9NVun/S785AP05vKkXZEFYxqG6EW012U4oLcFl5MySFajYXRYbuUpH6AY+HP8
38
+ voD0MPg1DssDLKwXyt1eKD/+Fq0bFWhwVM/1XiAXL7lyYUyOq24KHgQ2Csg=
39
+ -----END CERTIFICATE-----
40
+ date: 2024-05-04 00:00:00.000000000 Z
14
41
  dependencies: []
15
-
16
- description: "\n The WTF gem provides a Ruby class to convert between standard\n time and World Time Format. For more information, visit\n http://www.worldtimeformat.com\n "
17
- email: techiferous@gmail.com
42
+ description:
43
+ email:
18
44
  executables: []
19
-
20
45
  extensions: []
21
-
22
- extra_rdoc_files:
23
- - LICENSE
24
- - README
25
- files:
26
- - CHANGELOG
27
- - LICENSE
28
- - README
29
- - Rakefile
46
+ extra_rdoc_files: []
47
+ files:
30
48
  - lib/wtf.rb
31
- - test/test_helper.rb
32
- - test/wtf_test.rb
33
- has_rdoc: true
34
- homepage: http://github.com/techiferous/wtf
35
- licenses: []
36
-
37
- post_install_message:
38
- rdoc_options:
39
- - --charset=UTF-8
40
- require_paths:
49
+ - lib/wtf/is_it_doing.rb
50
+ - lib/wtf/version.rb
51
+ - license.md
52
+ - readme.md
53
+ homepage: https://github.com/ioquatix/wtf
54
+ licenses:
55
+ - MIT
56
+ metadata:
57
+ documentation_uri: https://ioquatix.github.io/wtf/
58
+ funding_uri: https://github.com/sponsors/ioquatix/
59
+ source_code_uri: https://github.com/ioquatix/wtf.git
60
+ post_install_message:
61
+ rdoc_options: []
62
+ require_paths:
41
63
  - lib
42
- required_ruby_version: !ruby/object:Gem::Requirement
43
- requirements:
64
+ required_ruby_version: !ruby/object:Gem::Requirement
65
+ requirements:
44
66
  - - ">="
45
- - !ruby/object:Gem::Version
46
- version: "0"
47
- version:
48
- required_rubygems_version: !ruby/object:Gem::Requirement
49
- requirements:
67
+ - !ruby/object:Gem::Version
68
+ version: '3.1'
69
+ required_rubygems_version: !ruby/object:Gem::Requirement
70
+ requirements:
50
71
  - - ">="
51
- - !ruby/object:Gem::Version
52
- version: "0"
53
- version:
54
- requirements:
55
- - none
56
- rubyforge_project:
57
- rubygems_version: 1.3.5
58
- signing_key:
59
- specification_version: 3
60
- summary: Converts between World Time Format and standard dates and times.
61
- test_files:
62
- - test/test_helper.rb
63
- - test/wtf_test.rb
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ requirements: []
75
+ rubygems_version: 3.5.3
76
+ signing_key:
77
+ specification_version: 4
78
+ summary: WTF is your program doing?
79
+ test_files: []
metadata.gz.sig ADDED
Binary file
data/CHANGELOG DELETED
@@ -1,2 +0,0 @@
1
- 0.0.1 (November 29, 2009)
2
- * Initial release.
data/README DELETED
@@ -1,17 +0,0 @@
1
- = World Time Format Converter
2
-
3
- == Description
4
-
5
- The WTF gem provides a Ruby class to convert between standard
6
- time and World Time Format. For more information, visit
7
- http://www.worldtimeformat.com
8
-
9
- == Examples
10
-
11
- WTF::Date.new("FIWIT:NAAAA").as_utc # converts a WTF datetime to a Ruby Time object
12
- WTF::Date.new(time).as_wtf # converts from a Ruby Time object to a WTF string
13
- WTF::Date.now.as_wtf # returns a WTF string representing the current datetime
14
- WTF::Date.now.date_part # returns a WTF string representing the current date
15
- WTF::Date.now.time_part # returns a WTF string representing the current time
16
- WTF::Date.convert("FIWIT:NAAAA") # convenience method for converting
17
- WTF::Date.convert(time) # convenience method for converting
data/Rakefile DELETED
@@ -1,48 +0,0 @@
1
- require 'rake'
2
- require 'rake/testtask'
3
- require 'rake/rdoctask'
4
-
5
- desc 'Default: run unit tests.'
6
- task :default => :test
7
-
8
- desc 'Test WTF.'
9
- Rake::TestTask.new(:test) do |t|
10
- t.libs << 'lib'
11
- t.pattern = 'test/**/*_test.rb'
12
- t.verbose = true
13
- end
14
-
15
- desc 'Generate documentation for WTF.'
16
- Rake::RDocTask.new(:rdoc) do |rdoc|
17
- rdoc.rdoc_dir = 'rdoc'
18
- rdoc.title = 'WTF'
19
- rdoc.rdoc_files.include('README')
20
- rdoc.rdoc_files.include('lib/**/*.rb')
21
- end
22
-
23
- begin
24
- require 'jeweler'
25
- Jeweler::Tasks.new do |s|
26
- s.name = "wtf"
27
- s.version = "0.0.1"
28
- s.author = "Wyatt Greene"
29
- s.email = "techiferous@gmail.com"
30
- s.summary = "Converts between World Time Format and standard dates and times."
31
- s.description = %Q{
32
- The WTF gem provides a Ruby class to convert between standard
33
- time and World Time Format. For more information, visit
34
- http://www.worldtimeformat.com
35
- }
36
- s.require_path = "lib"
37
- s.files = ["lib/wtf.rb", "LICENSE", "Rakefile", "README",
38
- "CHANGELOG",
39
- "test/wtf_test.rb", "test/test_helper.rb"]
40
- s.homepage = "http://github.com/techiferous/wtf"
41
- s.requirements << "none"
42
- s.has_rdoc = true
43
- s.test_files = Dir.glob("test/**/*.rb")
44
- end
45
- Jeweler::GemcutterTasks.new
46
- rescue LoadError
47
- puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
48
- end
data/test/test_helper.rb DELETED
@@ -1,3 +0,0 @@
1
- require 'test/unit'
2
- require 'rubygems'
3
- require 'redgreen'
data/test/wtf_test.rb DELETED
@@ -1,138 +0,0 @@
1
- require 'test/test_helper'
2
- require 'wtf'
3
-
4
- class WtfTest < Test::Unit::TestCase
5
-
6
- #--------------------------#
7
- # Testing private methods. #
8
- #--------------------------#
9
-
10
- def test_alphabase_conversion_with_whole_numbers
11
- assert_equal "A", WTF::Date.send(:decimal_to_alphabase, 0)
12
- assert_equal "B", WTF::Date.send(:decimal_to_alphabase, 1)
13
- assert_equal "C", WTF::Date.send(:decimal_to_alphabase, 2)
14
- assert_equal "J", WTF::Date.send(:decimal_to_alphabase, 9)
15
- assert_equal "Z", WTF::Date.send(:decimal_to_alphabase, 25)
16
- assert_equal "BA", WTF::Date.send(:decimal_to_alphabase, 26)
17
- assert_equal "BB", WTF::Date.send(:decimal_to_alphabase, 27)
18
- assert_equal "BAA", WTF::Date.send(:decimal_to_alphabase, 676)
19
- assert_equal "BAB", WTF::Date.send(:decimal_to_alphabase, 677)
20
- assert_equal "BAC", WTF::Date.send(:decimal_to_alphabase, 678)
21
- end
22
-
23
- def test_alphabase_conversion_with_negative_numbers
24
- assert_equal "-B", WTF::Date.send(:decimal_to_alphabase, -1)
25
- assert_equal "-C", WTF::Date.send(:decimal_to_alphabase, -2)
26
- assert_equal "-BB", WTF::Date.send(:decimal_to_alphabase, -27)
27
- assert_equal "-BAA", WTF::Date.send(:decimal_to_alphabase, -676)
28
- end
29
-
30
- def test_alphabase_conversion_with_floats
31
- assert_raise ArgumentError do
32
- WTF::Date.send(:decimal_to_alphabase, 7.7)
33
- end
34
- end
35
-
36
- def test_time_to_wtf
37
- assert_equal "AAAAA", WTF::Date.send(:time_to_wtf, 0) # midnight
38
- assert_equal "NAAAA", WTF::Date.send(:time_to_wtf, 12*60*60*1000) # noon
39
- assert_equal "BAAAA", WTF::Date.send(:time_to_wtf, 3323077)
40
- end
41
-
42
- #---------------------#
43
- # Testing public API. #
44
- #---------------------#
45
-
46
- def test_converting_to_wtf
47
-
48
- time = Time.utc(1970, 1, 1, 0)
49
- wtf = WTF::Date.new(time)
50
- assert_equal "FIWIT", wtf.date_part
51
- assert_equal "NAAAA", wtf.time_part
52
- assert_equal "FIWIT:NAAAA", wtf.as_wtf
53
-
54
- time = Time.utc(1969, 12, 31, 12)
55
- wtf = WTF::Date.new(time)
56
- assert_equal "FIWIT", wtf.date_part
57
- assert_equal "AAAAA", wtf.time_part
58
- assert_equal "FIWIT:AAAAA", wtf.as_wtf
59
-
60
- time = Time.utc(2002, 7, 10, 12)
61
- wtf = WTF::Date.new(time)
62
- assert_equal "FJNXQ", wtf.date_part
63
- assert_equal "AAAAA", wtf.time_part
64
- assert_equal "FJNXQ:AAAAA", wtf.as_wtf
65
-
66
- time = Time.utc(2002, 7, 10, 13, 55, 1, 777000)
67
- wtf = WTF::Date.new(time)
68
- assert_equal "FJNXQ", wtf.date_part
69
- assert_equal "CCAAA", wtf.time_part
70
- assert_equal "FJNXQ:CCAAA", wtf.as_wtf
71
-
72
- end
73
-
74
- def test_converting_to_standard_time
75
- time = Time.utc(1970, 1, 1, 0)
76
- assert_equal time, WTF::Date.new("FIWIT:NAAAA").as_utc
77
- assert_equal time, WTF::Date.new("FIWIT:NAAA").as_utc
78
- assert_equal time, WTF::Date.new("FIWIT:NAA").as_utc
79
- assert_equal time, WTF::Date.new("FIWIT:NA").as_utc
80
- assert_equal time, WTF::Date.new("FIWIT:N").as_utc
81
- time = Time.utc(1969, 12, 31, 12)
82
- assert_equal time, WTF::Date.new("FIWIT:AAAAA").as_utc
83
- assert_equal time, WTF::Date.new("FIWIT:AAAA").as_utc
84
- assert_equal time, WTF::Date.new("FIWIT:AAA").as_utc
85
- assert_equal time, WTF::Date.new("FIWIT:AA").as_utc
86
- assert_equal time, WTF::Date.new("FIWIT:A").as_utc
87
- assert_equal time, WTF::Date.new("FIWIT:").as_utc
88
- assert_equal time, WTF::Date.new("IWIT:").as_utc
89
- assert_equal time, WTF::Date.new("IWIT:A").as_utc
90
- assert_equal time, WTF::Date.new("IWIT:AA").as_utc
91
- time = Time.utc(2002, 7, 10, 12)
92
- assert_equal time, WTF::Date.new("FJNXQ:AAAAA").as_utc
93
- assert_equal time, WTF::Date.new("FJNXQ:").as_utc
94
- assert_equal time, WTF::Date.new("NXQ:").as_utc
95
- time = Time.utc(2002, 7, 10, 13, 55, 1, 777000)
96
- assert_in_delta time.to_f, WTF::Date.new("FJNXQ:CCAAA").as_utc.to_f, 0.006
97
- assert_in_delta time.to_f, WTF::Date.new("FJNXQ:CC").as_utc.to_f, 0.006
98
- assert_equal 12, WTF::Date.new(":AA").as_utc.hour
99
- assert_equal 0, WTF::Date.new(":AA").as_utc.min
100
- assert_equal 0, WTF::Date.new(":N").as_utc.hour
101
- assert_equal 0, WTF::Date.new(":N").as_utc.min
102
- assert_equal 0, WTF::Date.new("N").as_utc.hour
103
- assert_equal 0, WTF::Date.new("N").as_utc.min
104
- assert_equal 12, WTF::Date.new(":").as_utc.hour
105
- assert_equal 0, WTF::Date.new(":").as_utc.min
106
- assert_raise ArgumentError do
107
- WTF::Date.new("").as_utc
108
- end
109
- assert_raise ArgumentError do
110
- WTF::Date.new("ABCDEF:ABC").as_utc # date part can't be longer than five characters
111
- end
112
- assert_nothing_raised do
113
- WTF::Date.new("FJCDE:ABCDEFGHIJ").as_utc # time part can be longer than five characters
114
- end
115
- end
116
-
117
- def test_now
118
- wtf = WTF::Date.now
119
- wtf2 = WTF::Date.now
120
- time = wtf.as_utc
121
- time2 = wtf2.as_utc
122
- past = Time.utc(2009, 11, 28)
123
- future = Time.utc(2030, 1, 12)
124
- assert time <= time2
125
- assert time < future
126
- assert time > past
127
- end
128
-
129
- def test_convert
130
- time = Time.utc(1970, 1, 1, 0)
131
- assert_equal time, WTF::Date.convert("FIWIT:NAAAA")
132
- assert_equal time, WTF::Date.convert("FIWIT:NAA")
133
- assert_equal time, WTF::Date.convert("FIWIT:N")
134
- assert_equal time, WTF::Date.convert("IWIT:N")
135
- assert_equal "FIWIT:NAAAA", WTF::Date.convert(time)
136
- end
137
-
138
- end