date-casually 0.1.0 → 0.2.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.
- data/README.rdoc +2 -2
- data/VERSION +1 -1
- data/date-casually.gemspec +9 -12
- data/lib/date-casually/calculator.rb +99 -5
- data/lib/date-casually/config.rb +43 -2
- data/lib/date-casually/{translators → translator}/day_of_week.rb +2 -2
- data/lib/date-casually/{translators → translator}/days.rb +2 -2
- data/lib/date-casually/{translators → translator}/months.rb +2 -3
- data/lib/date-casually/{translators → translator}/weeks.rb +2 -2
- data/lib/date-casually/{translators → translator}/years.rb +2 -2
- data/lib/date-casually/translator.rb +53 -12
- data/lib/date-casually.rb +6 -5
- data/lib/extensions/date.rb +36 -0
- data/lib/locale/en.yml +92 -93
- data/lib/util/alphabetize_yaml.rb +5 -1
- data/test/helper.rb +5 -1
- metadata +9 -12
- data/lib/locale/en.yml.sorted +0 -85
- data/test/timeline.rb +0 -11
data/README.rdoc
CHANGED
@@ -24,8 +24,8 @@ If you'd like to change what increments of time DateCasually returns you can use
|
|
24
24
|
|
25
25
|
You can also pass in multiple options:
|
26
26
|
|
27
|
-
(Date.today +
|
28
|
-
#=> '
|
27
|
+
(Date.today + 12).casual(:as => :days, :months, :years)
|
28
|
+
#=> 'tomorrow'
|
29
29
|
|
30
30
|
The default :as options for DatCasually are:
|
31
31
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.2.0
|
data/date-casually.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{date-casually}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.2.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Theo Mills"]
|
12
|
-
s.date = %q{2010-
|
12
|
+
s.date = %q{2010-09-05}
|
13
13
|
s.description = %q{If you've never liked (and always seem to forget) the name of the Rails distance_of_time_in_words_to_now helper method, then it's time to date casually.}
|
14
14
|
s.email = %q{twmills@twmills.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -28,14 +28,13 @@ Gem::Specification.new do |s|
|
|
28
28
|
"lib/date-casually/calculator.rb",
|
29
29
|
"lib/date-casually/config.rb",
|
30
30
|
"lib/date-casually/translator.rb",
|
31
|
-
"lib/date-casually/
|
32
|
-
"lib/date-casually/
|
33
|
-
"lib/date-casually/
|
34
|
-
"lib/date-casually/
|
35
|
-
"lib/date-casually/
|
31
|
+
"lib/date-casually/translator/day_of_week.rb",
|
32
|
+
"lib/date-casually/translator/days.rb",
|
33
|
+
"lib/date-casually/translator/months.rb",
|
34
|
+
"lib/date-casually/translator/weeks.rb",
|
35
|
+
"lib/date-casually/translator/years.rb",
|
36
36
|
"lib/extensions/date.rb",
|
37
37
|
"lib/locale/en.yml",
|
38
|
-
"lib/locale/en.yml.sorted",
|
39
38
|
"lib/util/alphabetize_yaml.rb",
|
40
39
|
"test/helper.rb",
|
41
40
|
"test/test_calculator.rb",
|
@@ -45,8 +44,7 @@ Gem::Specification.new do |s|
|
|
45
44
|
"test/test_months.rb",
|
46
45
|
"test/test_translator.rb",
|
47
46
|
"test/test_weeks.rb",
|
48
|
-
"test/test_years.rb"
|
49
|
-
"test/timeline.rb"
|
47
|
+
"test/test_years.rb"
|
50
48
|
]
|
51
49
|
s.homepage = %q{http://github.com/twmills/date-casually}
|
52
50
|
s.rdoc_options = ["--charset=UTF-8"]
|
@@ -62,8 +60,7 @@ Gem::Specification.new do |s|
|
|
62
60
|
"test/test_months.rb",
|
63
61
|
"test/test_translator.rb",
|
64
62
|
"test/test_weeks.rb",
|
65
|
-
"test/test_years.rb"
|
66
|
-
"test/timeline.rb"
|
63
|
+
"test/test_years.rb"
|
67
64
|
]
|
68
65
|
|
69
66
|
if s.respond_to? :specification_version then
|
@@ -1,43 +1,137 @@
|
|
1
1
|
module DateCasually
|
2
2
|
|
3
|
-
# Contains
|
4
|
-
# today and a supplied date.
|
5
|
-
|
6
|
-
|
3
|
+
# Contains convenience calculations for determing the distance between
|
4
|
+
# today and a supplied date. All methods are module methods and should be called
|
5
|
+
# on the Calculator module.
|
6
|
+
# For example:
|
7
|
+
#
|
8
|
+
# DateCasually::Calculator.number_of_weeks_from_today(Date.today + 28)
|
9
|
+
# #=> 4
|
10
|
+
#
|
11
|
+
module Calculator
|
12
|
+
|
13
|
+
# Returns the number of full weeks from the supplied date to today's date.
|
14
|
+
#
|
15
|
+
# date - The Date used to compare against today's date and determine the number
|
16
|
+
# of weeks between the two.
|
17
|
+
#
|
18
|
+
# Examples (if today is 2010-09-03)
|
19
|
+
#
|
20
|
+
# DateCasually::Calculator.number_of_weeks_from_today(Date.today + 28)
|
21
|
+
# #=> 4
|
22
|
+
#
|
23
|
+
# DateCasually::Calculator.number_of_weeks_from_today(Date.today)
|
24
|
+
# #=> 0
|
25
|
+
#
|
26
|
+
# Returns the number of weeks between the supplied date and today.
|
7
27
|
def self.number_of_weeks_from_today(date)
|
8
28
|
((Date.today - date) / 7).to_i.abs
|
9
29
|
end
|
10
30
|
|
31
|
+
# Returns the number of months from to today's date to the supplied date.
|
32
|
+
#
|
33
|
+
# date - The Date used to compare against today's date and determine the number
|
34
|
+
# of months between the two.
|
35
|
+
#
|
36
|
+
# Examples (if today is 2010-09-03)
|
37
|
+
#
|
38
|
+
# DateCasually::Calculator.number_of_months_from_today(Date.today + 28)
|
39
|
+
# #=> 1
|
40
|
+
#
|
41
|
+
# Returns the number of months between the supplied date and today.
|
11
42
|
def self.number_of_months_from_today(date)
|
12
43
|
((Date.today.month - date.month) + 12 * (Date.today.year - date.year)).abs
|
13
44
|
end
|
14
45
|
|
46
|
+
# Returns the number of years from to today's date to the supplied date.
|
47
|
+
#
|
48
|
+
# date - The Date used to compare against today's date and determine the number
|
49
|
+
# of years between the two.
|
50
|
+
#
|
51
|
+
# Examples (if today is 2010-09-03)
|
52
|
+
#
|
53
|
+
# DateCasually::Calculator.number_of_months_from_today(Date.today + 365)
|
54
|
+
# #=> 1
|
55
|
+
#
|
56
|
+
# Returns the number of years between the supplied date and today.
|
15
57
|
def self.number_of_years_from_today(date)
|
16
58
|
years_diff = (Date.today.year - date.year).abs
|
17
59
|
end
|
18
60
|
|
61
|
+
# Returns a range of dates for the current week. Starts with Sunday and ends
|
62
|
+
# on Saturday.
|
63
|
+
#
|
64
|
+
# Examples (if today is 2010-09-03)
|
65
|
+
#
|
66
|
+
# DateCasually::Calculator.this_week_range.to_s #to_s used for clarity
|
67
|
+
# #=> "2010-08-29..2010-09-04"
|
68
|
+
#
|
69
|
+
# Returns a range of dates for the current week.
|
19
70
|
def self.this_week_range
|
20
71
|
self.this_past_sunday..(self.this_past_sunday + 6)
|
21
72
|
end
|
22
73
|
|
74
|
+
# Returns a range of dates for the coming week. Starts with Sunday and ends
|
75
|
+
# on Saturday.
|
76
|
+
#
|
77
|
+
# Examples (if today is 2010-09-03)
|
78
|
+
#
|
79
|
+
# DateCasually::Calculator.next_week_range.to_s #to_s used for clarity
|
80
|
+
# #=> "2010-09-05..2010-09-11"
|
81
|
+
#
|
82
|
+
# Returns a range of dates for the coming week.
|
23
83
|
def self.next_week_range
|
24
84
|
self.next_sunday..(self.next_sunday + 6)
|
25
85
|
end
|
26
|
-
|
86
|
+
|
87
|
+
# Returns a range of dates for the previous week. Starts with Sunday and ends
|
88
|
+
# on Saturday.
|
89
|
+
#
|
90
|
+
# Examples (if today is 2010-09-03)
|
91
|
+
#
|
92
|
+
# DateCasually::Calculator.last_week_range.to_s #to_s used for clarity
|
93
|
+
# #=> "2010-08-22..2010-08-28"
|
94
|
+
#
|
95
|
+
# Returns a range of dates for the previous week.
|
27
96
|
def self.last_week_range
|
28
97
|
self.last_sunday..(self.last_sunday + 6)
|
29
98
|
end
|
30
99
|
|
100
|
+
# Returns a range of dates for the coming week. Starts with Sunday and ends
|
101
|
+
# on Saturday.
|
102
|
+
#
|
103
|
+
# Examples (if today is 2010-09-03)
|
104
|
+
#
|
105
|
+
# DateCasually::Calculator.next_week_range.to_s #to_s used for clarity
|
106
|
+
# #=> "2010-09-05..2010-09-11"
|
107
|
+
#
|
108
|
+
# Returns a range of dates for the coming week.
|
31
109
|
def self.next_sunday
|
32
110
|
date = Date.today
|
33
111
|
(date.wday == 0) ? (date += 7) : (date += 1 until (date.wday == 0))
|
34
112
|
date
|
35
113
|
end
|
36
114
|
|
115
|
+
# Returns the date of last week's Sunday.
|
116
|
+
#
|
117
|
+
# Examples (if today is 2010-09-03)
|
118
|
+
#
|
119
|
+
# DateCasually::Calculator.last_sunday.to_s #to_s used for clarity
|
120
|
+
# #=> "2010-08-22"
|
121
|
+
#
|
122
|
+
# Returns the Date of last week's Sunday.
|
37
123
|
def self.last_sunday
|
38
124
|
self.this_past_sunday - 7
|
39
125
|
end
|
40
126
|
|
127
|
+
# Returns the date of the most recent Sunday in the past.
|
128
|
+
#
|
129
|
+
# Examples (if today is 2010-09-03)
|
130
|
+
#
|
131
|
+
# DateCasually::Calculator.this_past_sunday.to_s #to_s used for clarity
|
132
|
+
# #=> "2010-08-29"
|
133
|
+
#
|
134
|
+
# Returns the Date of the most recent Sunday in the past.
|
41
135
|
def self.this_past_sunday
|
42
136
|
date = Date.today
|
43
137
|
(date.wday == 0) ? date : (date -= 1 until (date.wday == 0))
|
data/lib/date-casually/config.rb
CHANGED
@@ -1,14 +1,55 @@
|
|
1
1
|
module DateCasually
|
2
|
-
|
2
|
+
|
3
|
+
# Contains global configuration options for DateCasually. These options
|
4
|
+
# may be changed globally at runtime by using the designated class method.
|
5
|
+
# For example:
|
6
|
+
#
|
7
|
+
# DateCasually::Config.as :years
|
8
|
+
# (Date.today + 2).casual
|
9
|
+
# #=> "less than a year from now"
|
10
|
+
#
|
11
|
+
module Config
|
12
|
+
|
3
13
|
class << self
|
14
|
+
|
15
|
+
# Gets and sets a map that tells DateCasually which translation options to use
|
16
|
+
# when translating the current date. Values should be passed as an array of symbols.
|
17
|
+
# Possible values are :day, :week, :month, :year, :day_of_week.
|
18
|
+
#
|
19
|
+
# Examples:
|
20
|
+
#
|
21
|
+
# date = Date.new(2010, 8, 30)
|
22
|
+
#
|
23
|
+
# (date + 6).casual(:day_of_week)
|
24
|
+
# #=> 'next week'
|
25
|
+
#
|
26
|
+
# (date + 1).casual(:months)
|
27
|
+
# #=> 'less than a month from now'
|
28
|
+
#
|
29
|
+
# (date + 660).casual(:months)
|
30
|
+
# #=> '21 months from now'
|
31
|
+
#
|
32
|
+
# (date + 660).casual(:months, :years)
|
33
|
+
# #=> 'a couple of years from now'
|
34
|
+
#
|
4
35
|
attr_accessor :as
|
5
36
|
end
|
6
37
|
|
38
|
+
# Resets the classes configuration options back to their defaults. Used
|
39
|
+
# primarily to reset the class configuration options when the module
|
40
|
+
# gets loaded.
|
41
|
+
#
|
42
|
+
# Example:
|
43
|
+
#
|
44
|
+
# self.reset
|
45
|
+
#
|
46
|
+
# Returns nothing.
|
7
47
|
def self.reset
|
8
48
|
self.as = [:days, :weeks, :months, :years]
|
9
49
|
end
|
10
50
|
|
11
|
-
#
|
51
|
+
# Reset the first time we are loaded.
|
12
52
|
self.reset
|
53
|
+
|
13
54
|
end
|
14
55
|
end
|
@@ -1,14 +1,20 @@
|
|
1
1
|
module DateCasually
|
2
2
|
|
3
|
-
# The
|
4
|
-
#
|
5
|
-
class
|
3
|
+
# The core of the date-casually functionality, translating the supplied date to
|
4
|
+
# its casual equivalent. This module is primarily intended to be used from the
|
5
|
+
# DateCasually Date extension class. All methods are module methods and should be called
|
6
|
+
# on the Translator module.
|
7
|
+
# For example:
|
8
|
+
#
|
9
|
+
# DateCasually::Translator.number_of_weeks_from_today(Date.today + 28)
|
10
|
+
# #=> 4
|
11
|
+
#
|
12
|
+
module Translator
|
6
13
|
|
7
14
|
# The possible options and order of the :as toggle
|
8
15
|
AS_OPTIONS = [:days, :day_of_week, :weeks, :months, :years]
|
9
16
|
|
10
|
-
#
|
11
|
-
# This method takes the supplied date and determines how it should be translated
|
17
|
+
# Public: Takes the supplied date and determines how it should be translated
|
12
18
|
# into its casual equivalent. If the :as option is passed with a valid value,
|
13
19
|
# then the date is evaluated against that scope, e.g. :as=>:day_of_week.
|
14
20
|
# Otherwise, the Translator iterates through all the available scopes until a
|
@@ -20,37 +26,72 @@ module DateCasually
|
|
20
26
|
#
|
21
27
|
def self.casual(date, options = {})
|
22
28
|
|
23
|
-
#
|
24
|
-
# the
|
29
|
+
# Loop through the :as options and try to translate the date
|
30
|
+
# for the given options.
|
25
31
|
translator = nil
|
26
32
|
self.as_options(options).each do |option|
|
27
|
-
translator = self.
|
33
|
+
translator = self.get_module(option)
|
28
34
|
translation = translator.translate(date)
|
29
35
|
return translation unless translation.nil?
|
30
36
|
end
|
31
37
|
|
32
|
-
# If no
|
38
|
+
# If no translations are found, use our last translator to create
|
33
39
|
# explicit counts. I.e. 470 days ago, 46 months from now, 4 years from now, etc.
|
34
40
|
unless translator.nil?
|
35
41
|
translation = translator.translate_count(date)
|
36
42
|
return translation unless translation.nil?
|
37
43
|
end
|
38
44
|
|
45
|
+
# This should never be encountered. If it is, we've got a bug and want to
|
46
|
+
# be vocal about it.
|
39
47
|
raise "[date-casually] No ruleset defined for this date: #{date}"
|
40
48
|
end
|
41
49
|
|
50
|
+
# Determines which :as options to use during translation. If no :as option is passed
|
51
|
+
# at runtime, use the definition in the Config module. Since the :as values must occur
|
52
|
+
# in a chronological order (e.g. :days, :weeks, :months), this method ensures the values
|
53
|
+
# are correctly ordered before returning them. It also parses out any values that aren't
|
54
|
+
# found in the AS_OPTIONS constant.
|
55
|
+
#
|
56
|
+
# options - Hashmap of DateCasually options.
|
42
57
|
#
|
43
|
-
#
|
58
|
+
# Example:
|
59
|
+
# options[:as] = :weeks, :days, :years, :months, :foobar
|
60
|
+
# DateCasually::Translator.as_options(options)
|
61
|
+
# # => :days, :weeks, :days, :months, :years
|
62
|
+
#
|
63
|
+
# Returns Array of :as configuration options, sorted like the AS_OPTIONS array.
|
44
64
|
def self.as_options(options)
|
45
65
|
as = []
|
46
66
|
as << (!options.nil? && options.has_key?(:as) ? options[:as] : DateCasually::Config.as)
|
47
67
|
self::AS_OPTIONS & as.flatten
|
48
68
|
end
|
49
69
|
|
50
|
-
|
51
|
-
|
70
|
+
# Dynamically returns the translator module that corresponds to the
|
71
|
+
# supplied symbol. The symbol should correspond to one of those found
|
72
|
+
# in the AS_OPTIONS array, though this is not enforced.
|
73
|
+
#
|
74
|
+
# sym - Symbol that corresponds to the supplied symbol.
|
75
|
+
#
|
76
|
+
# Example:
|
77
|
+
# DateCasually::Translator.get_module(:days)
|
78
|
+
# # => Days
|
79
|
+
#
|
80
|
+
# Returns Module that corresponds to the supplied symbol
|
81
|
+
def self.get_module(sym)
|
82
|
+
const_get(self.camelcase(sym.to_s))
|
52
83
|
end
|
53
84
|
|
85
|
+
# Converts a string to the camel case format, removing any underscores and upcasing
|
86
|
+
# the character that immediately follow them.
|
87
|
+
#
|
88
|
+
# string - String to be converted to camel case.
|
89
|
+
#
|
90
|
+
# Example:
|
91
|
+
# DateCasually::Translator.camelcase("day_of_week")
|
92
|
+
# # => "DayOfWeek"
|
93
|
+
#
|
94
|
+
# Returns String in the camelcase format
|
54
95
|
def self.camelcase(string)
|
55
96
|
string.downcase.gsub(/\b[a-z]|_+[a-z]/) { |a| a.upcase }.gsub(/\s|_/,'')
|
56
97
|
end
|
data/lib/date-casually.rb
CHANGED
@@ -3,14 +3,15 @@ $LOAD_PATH.unshift(File.dirname(__FILE__))
|
|
3
3
|
require 'rubygems'
|
4
4
|
require 'date'
|
5
5
|
require 'i18n'
|
6
|
+
|
6
7
|
require "date-casually/config"
|
7
8
|
require "date-casually/calculator"
|
8
9
|
require "date-casually/translator"
|
9
|
-
require "date-casually/
|
10
|
-
require "date-casually/
|
11
|
-
require "date-casually/
|
12
|
-
require "date-casually/
|
13
|
-
require "date-casually/
|
10
|
+
require "date-casually/translator/days"
|
11
|
+
require "date-casually/translator/weeks"
|
12
|
+
require "date-casually/translator/months"
|
13
|
+
require "date-casually/translator/day_of_week"
|
14
|
+
require "date-casually/translator/years"
|
14
15
|
require "extensions/date"
|
15
16
|
|
16
17
|
# load up translations
|
data/lib/extensions/date.rb
CHANGED
@@ -1,4 +1,40 @@
|
|
1
|
+
# The Date class gets monkey-patched (gasp!) to activate DateCasually features
|
2
|
+
# via the 'casual' method.
|
1
3
|
class Date
|
4
|
+
|
5
|
+
# Public: Translates the current date object (self) into its language-based
|
6
|
+
# equivalent.
|
7
|
+
#
|
8
|
+
# options - List of options to control what the casual method outputs.
|
9
|
+
# :as - Tells DateCasually which date ranges to use when translating
|
10
|
+
# the current date. Values should be passed an array of symbols.
|
11
|
+
# Possible values are :day, :week, :month, :year, :day_of_week.
|
12
|
+
#
|
13
|
+
# Examples
|
14
|
+
# date = Date.new(2010, 8, 30)
|
15
|
+
#
|
16
|
+
# (date + 1).casual
|
17
|
+
# #=> 'tomorrow'
|
18
|
+
#
|
19
|
+
# (date - 1).casual
|
20
|
+
# #=> 'yesterday'
|
21
|
+
#
|
22
|
+
# (date + 6).casual
|
23
|
+
# #=> 'next week'
|
24
|
+
#
|
25
|
+
# (date + 6).casual(:day_of_week)
|
26
|
+
# #=> 'next week'
|
27
|
+
#
|
28
|
+
# (date + 1).casual(:months)
|
29
|
+
# #=> 'less than a month from now'
|
30
|
+
#
|
31
|
+
# (date + 660).casual(:months)
|
32
|
+
# #=> '21 months from now'
|
33
|
+
#
|
34
|
+
# (date + 660).casual(:months, :years)
|
35
|
+
# #=> 'a couple of years from now'
|
36
|
+
#
|
37
|
+
# Returns language translation of the current date.
|
2
38
|
def casual(options = {})
|
3
39
|
DateCasually::Translator.casual(self, options)
|
4
40
|
end
|
data/lib/locale/en.yml
CHANGED
@@ -1,93 +1,92 @@
|
|
1
|
-
en:
|
2
|
-
date:
|
3
|
-
casual:
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
couple_of_years_from_now: "a couple of years from now"
|
1
|
+
en:
|
2
|
+
date:
|
3
|
+
casual:
|
4
|
+
a_week_ago: a week ago
|
5
|
+
a_year_ago: a year ago
|
6
|
+
a_year_from_now: a year from now
|
7
|
+
about_a_week_ago: about a week ago
|
8
|
+
about_a_week_from_now: about a week from now
|
9
|
+
couple_of_days_ago: a couple of days ago
|
10
|
+
couple_of_days_from_now: a couple of days from now
|
11
|
+
couple_of_months_ago: a couple of months ago
|
12
|
+
couple_of_months_from_now: a couple of months from now
|
13
|
+
couple_of_weeks_ago: a couple of weeks ago
|
14
|
+
couple_of_weeks_from_now: a couple of weeks from now
|
15
|
+
couple_of_years_ago: a couple of years ago
|
16
|
+
couple_of_years_from_now: a couple of years from now
|
17
|
+
days_ago: %{number} days ago
|
18
|
+
days_from_now: %{number} days from now
|
19
|
+
exactly_one_month_ago: exactly one month ago
|
20
|
+
exactly_one_month_from_now: exactly one month from now
|
21
|
+
in_a_couple_of_days: in a couple of days
|
22
|
+
in_a_couple_of_weeks: in a couple of weeks
|
23
|
+
last_month: last month
|
24
|
+
last_wday_0: last Sunday
|
25
|
+
last_wday_1: last Monday
|
26
|
+
last_wday_2: last Tuesday
|
27
|
+
last_wday_3: last Wednesday
|
28
|
+
last_wday_4: last Thursday
|
29
|
+
last_wday_5: last Friday
|
30
|
+
last_wday_6: last Saturday
|
31
|
+
last_week: last week
|
32
|
+
last_year: last year
|
33
|
+
less_than_a_month_ago: less than a month ago
|
34
|
+
less_than_a_month_from_now: less than a month from now
|
35
|
+
less_than_a_week_ago: less than a week ago
|
36
|
+
less_than_a_week_from_now: less than a week from now
|
37
|
+
less_than_a_year_ago: less than a year ago
|
38
|
+
less_than_a_year_from_now: less than a year from now
|
39
|
+
months_ago: %{number} months ago
|
40
|
+
months_from_now: %{number} months from now
|
41
|
+
more_than_a_month_ago: more than a month ago
|
42
|
+
more_than_a_month_from_now: more than a month from now
|
43
|
+
more_than_a_week_ago: more than a week ago
|
44
|
+
more_than_a_week_from_now: more than a week from now
|
45
|
+
more_than_a_year_ago: more than a year ago
|
46
|
+
more_than_a_year_from_now: more than a year from now
|
47
|
+
next_month: next month
|
48
|
+
next_wday_0: next Sunday
|
49
|
+
next_wday_1: next Monday
|
50
|
+
next_wday_2: next Tuesday
|
51
|
+
next_wday_3: next Wednesday
|
52
|
+
next_wday_4: next Thursday
|
53
|
+
next_wday_5: next Friday
|
54
|
+
next_wday_6: next Saturday
|
55
|
+
next_week: next week
|
56
|
+
next_year: next year
|
57
|
+
one_day_ago: one day ago
|
58
|
+
this_past_wday_0: this past Sunday
|
59
|
+
this_past_wday_1: this past Monday
|
60
|
+
this_past_wday_2: this past Tuesday
|
61
|
+
this_past_wday_3: this past Wednesday
|
62
|
+
this_past_wday_4: this past Thursday
|
63
|
+
this_past_wday_5: this past Friday
|
64
|
+
this_past_wday_6: this past Saturday
|
65
|
+
this_wday_0: this Sunday
|
66
|
+
this_wday_1: this Monday
|
67
|
+
this_wday_2: this Tuesday
|
68
|
+
this_wday_3: this Wednesday
|
69
|
+
this_wday_4: this Thursday
|
70
|
+
this_wday_5: this Friday
|
71
|
+
this_wday_6: this Saturday
|
72
|
+
today: today
|
73
|
+
tomorrow: tomorrow
|
74
|
+
wdays_ago_0: %{number} Sundays ago
|
75
|
+
wdays_ago_1: %{number} Mondays ago
|
76
|
+
wdays_ago_2: %{number} Tuesdays ago
|
77
|
+
wdays_ago_3: %{number} Wednesdays ago
|
78
|
+
wdays_ago_4: %{number} Thursdays ago
|
79
|
+
wdays_ago_5: %{number} Fridays ago
|
80
|
+
wdays_ago_6: %{number} Saturdays ago
|
81
|
+
wdays_from_now_0: %{number} Sundays from now
|
82
|
+
wdays_from_now_1: %{number} Mondays from now
|
83
|
+
wdays_from_now_2: %{number} Tuesdays from now
|
84
|
+
wdays_from_now_3: %{number} Wednesdays from now
|
85
|
+
wdays_from_now_4: %{number} Thursdays from now
|
86
|
+
wdays_from_now_5: %{number} Fridays from now
|
87
|
+
wdays_from_now_6: %{number} Saturdays from now
|
88
|
+
weeks_ago: %{number} weeks ago
|
89
|
+
weeks_from_now: %{number} weeks from now
|
90
|
+
years_ago: %{number} years ago
|
91
|
+
years_from_now: %{number} years from now
|
92
|
+
yesterday: yesterday
|
@@ -1,3 +1,7 @@
|
|
1
|
+
# This file is used to alphabetize the locale YAML files. It doesn't
|
2
|
+
# overwrite them, but instead creates sorted copies of them with a
|
3
|
+
# ".sorted" file # extension.
|
4
|
+
|
1
5
|
require 'yaml'
|
2
6
|
class Hash
|
3
7
|
def to_sorted_yaml( opts = {} )
|
@@ -21,7 +25,7 @@ class Hash
|
|
21
25
|
end
|
22
26
|
|
23
27
|
end
|
24
|
-
files = Dir.glob(File.join(
|
28
|
+
files = Dir.glob(File.join("..","locale","*.yml"))
|
25
29
|
|
26
30
|
files.each do |file|
|
27
31
|
hash = YAML::load(File.read(file))
|
data/test/helper.rb
CHANGED
@@ -12,10 +12,14 @@ t = Time.local(2008, 9, 1, 10, 5, 0)
|
|
12
12
|
Timecop.travel(t)
|
13
13
|
|
14
14
|
class Test::Unit::TestCase
|
15
|
+
|
16
|
+
# Returns a Date object from Chronic's Time object
|
15
17
|
def parse(string)
|
16
18
|
Date.parse(Chronic.parse(string).strftime('%b %d, %Y'))
|
17
19
|
end
|
18
|
-
|
20
|
+
|
21
|
+
# Convenience method to generate method names for both
|
22
|
+
# the test cases that include the :as option, and those that don't.
|
19
23
|
def self.method_name(name, options)
|
20
24
|
if (options != nil) && options.has_key?(:as)
|
21
25
|
"test_#{name}_as_#{options[:as]}"
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: date-casually
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 23
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
8
|
+
- 2
|
9
9
|
- 0
|
10
|
-
version: 0.
|
10
|
+
version: 0.2.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Theo Mills
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-
|
18
|
+
date: 2010-09-05 00:00:00 -05:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -87,14 +87,13 @@ files:
|
|
87
87
|
- lib/date-casually/calculator.rb
|
88
88
|
- lib/date-casually/config.rb
|
89
89
|
- lib/date-casually/translator.rb
|
90
|
-
- lib/date-casually/
|
91
|
-
- lib/date-casually/
|
92
|
-
- lib/date-casually/
|
93
|
-
- lib/date-casually/
|
94
|
-
- lib/date-casually/
|
90
|
+
- lib/date-casually/translator/day_of_week.rb
|
91
|
+
- lib/date-casually/translator/days.rb
|
92
|
+
- lib/date-casually/translator/months.rb
|
93
|
+
- lib/date-casually/translator/weeks.rb
|
94
|
+
- lib/date-casually/translator/years.rb
|
95
95
|
- lib/extensions/date.rb
|
96
96
|
- lib/locale/en.yml
|
97
|
-
- lib/locale/en.yml.sorted
|
98
97
|
- lib/util/alphabetize_yaml.rb
|
99
98
|
- test/helper.rb
|
100
99
|
- test/test_calculator.rb
|
@@ -105,7 +104,6 @@ files:
|
|
105
104
|
- test/test_translator.rb
|
106
105
|
- test/test_weeks.rb
|
107
106
|
- test/test_years.rb
|
108
|
-
- test/timeline.rb
|
109
107
|
has_rdoc: true
|
110
108
|
homepage: http://github.com/twmills/date-casually
|
111
109
|
licenses: []
|
@@ -150,4 +148,3 @@ test_files:
|
|
150
148
|
- test/test_translator.rb
|
151
149
|
- test/test_weeks.rb
|
152
150
|
- test/test_years.rb
|
153
|
-
- test/timeline.rb
|
data/lib/locale/en.yml.sorted
DELETED
@@ -1,85 +0,0 @@
|
|
1
|
-
en:
|
2
|
-
date:
|
3
|
-
casual:
|
4
|
-
a_week_ago: a week ago
|
5
|
-
a_year_ago: a year ago
|
6
|
-
a_year_from_now: a year from now
|
7
|
-
about_a_week_ago: about a week ago
|
8
|
-
about_a_week_from_now: about a week from now
|
9
|
-
couple_of_days_ago: a couple of days ago
|
10
|
-
couple_of_days_from_now: a couple of days from now
|
11
|
-
couple_of_months_ago: a couple of months ago
|
12
|
-
couple_of_months_from_now: a couple of months from now
|
13
|
-
couple_of_weeks_ago: a couple of weeks ago
|
14
|
-
couple_of_weeks_from_now: a couple of weeks from now
|
15
|
-
couple_of_years_ago: a couple of years ago
|
16
|
-
couple_of_years_from_now: a couple of years from now
|
17
|
-
days_ago: {{number}} days ago
|
18
|
-
days_from_now: {{number}} days from now
|
19
|
-
exactly_one_month_ago: exactly one month ago
|
20
|
-
exactly_one_month_from_now: exactly one month from now
|
21
|
-
in_a_couple_of_days: in a couple of days
|
22
|
-
in_a_couple_of_weeks: in a couple of weeks
|
23
|
-
last_month: last month
|
24
|
-
last_wday_0: last Sunday
|
25
|
-
last_wday_1: last Monday
|
26
|
-
last_wday_2: last Tuesday
|
27
|
-
last_wday_3: last Wednesday
|
28
|
-
last_wday_4: last Thursday
|
29
|
-
last_wday_5: last Friday
|
30
|
-
last_wday_6: last Saturday
|
31
|
-
last_week: last week
|
32
|
-
last_year: last year
|
33
|
-
less_than_a_month_ago: less than a month ago
|
34
|
-
less_than_a_month_from_now: less than a month from now
|
35
|
-
less_than_a_week_ago: less than a week ago
|
36
|
-
less_than_a_week_from_now: less than a week from now
|
37
|
-
less_than_a_year_ago: less than a year ago
|
38
|
-
less_than_a_year_from_now: less than a year from now
|
39
|
-
months_ago: {{number}} months ago
|
40
|
-
months_from_now: {{number}} months from now
|
41
|
-
more_than_a_month_ago: more than a month ago
|
42
|
-
more_than_a_month_from_now: more than a month from now
|
43
|
-
more_than_a_week_ago: more than a week ago
|
44
|
-
more_than_a_week_from_now: more than a week from now
|
45
|
-
more_than_a_year_ago: more than a year ago
|
46
|
-
more_than_a_year_from_now: more than a year from now
|
47
|
-
next_month: next month
|
48
|
-
next_wday_0: next Sunday
|
49
|
-
next_wday_1: next Monday
|
50
|
-
next_wday_2: next Tuesday
|
51
|
-
next_wday_3: next Wednesday
|
52
|
-
next_wday_4: next Thursday
|
53
|
-
next_wday_5: next Friday
|
54
|
-
next_wday_6: next Saturday
|
55
|
-
next_week: next week
|
56
|
-
next_year: next year
|
57
|
-
one_day_ago: one day ago
|
58
|
-
this_past_wday_0: this past Sunday
|
59
|
-
this_past_wday_1: this past Monday
|
60
|
-
this_past_wday_2: this past Tuesday
|
61
|
-
this_past_wday_3: this past Wednesday
|
62
|
-
this_past_wday_4: this past Thursday
|
63
|
-
this_past_wday_5: this past Friday
|
64
|
-
this_past_wday_6: this past Saturday
|
65
|
-
this_wday_0: this Sunday
|
66
|
-
this_wday_1: this Monday
|
67
|
-
this_wday_2: this Tuesday
|
68
|
-
this_wday_3: this Wednesday
|
69
|
-
this_wday_4: this Thursday
|
70
|
-
this_wday_5: this Friday
|
71
|
-
this_wday_6: this Saturday
|
72
|
-
today: today
|
73
|
-
tomorrow: tomorrow
|
74
|
-
wdays_ago_0: {{number}} Sundays ago
|
75
|
-
wdays_ago_1: {{number}} Mondays ago
|
76
|
-
wdays_ago_2: {{number}} Tuesdays ago
|
77
|
-
wdays_ago_3: {{number}} Wednesdays ago
|
78
|
-
wdays_ago_4: {{number}} Thursdays ago
|
79
|
-
wdays_ago_5: {{number}} Fridays ago
|
80
|
-
wdays_ago_6: {{number}} Saturdays ago
|
81
|
-
weeks_ago: {{number}} weeks ago
|
82
|
-
weeks_from_now: {{number}} weeks from now
|
83
|
-
years_ago: {{number}} years ago
|
84
|
-
years_from_now: {{number}} years from now
|
85
|
-
yesterday: yesterday
|
data/test/timeline.rb
DELETED
@@ -1,11 +0,0 @@
|
|
1
|
-
require 'helper'
|
2
|
-
# max = 400
|
3
|
-
# as = :week
|
4
|
-
# max.downto(1).each do |x|
|
5
|
-
# puts "+#{(Date.today + x).to_s} = #{(Date.today + x).casual(:as => as)}"
|
6
|
-
# end
|
7
|
-
# 1.upto(max).each do |x|
|
8
|
-
# puts "-#{(Date.today - x).to_s} = #{(Date.today - x).casual(:as => as)}"
|
9
|
-
# end
|
10
|
-
DateCasually::Config.as = :months
|
11
|
-
puts (Date.today + 1).casual
|