kronic 0.2.0 → 0.2.1
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/HISTORY +4 -0
- data/lib/kronic.rb +11 -11
- data/spec/kronic_spec.rb +7 -5
- metadata +6 -32
    
        data/HISTORY
    CHANGED
    
    
    
        data/lib/kronic.rb
    CHANGED
    
    | @@ -1,4 +1,4 @@ | |
| 1 | 
            -
            require ' | 
| 1 | 
            +
            require 'date'
         | 
| 2 2 |  | 
| 3 3 | 
             
            class Kronic
         | 
| 4 4 | 
             
              # Public: Converts a human readable day (Today, yesterday) to a Date.
         | 
| @@ -44,20 +44,20 @@ class Kronic | |
| 44 44 |  | 
| 45 45 | 
             
                # Examples
         | 
| 46 46 | 
             
                #
         | 
| 47 | 
            -
                #   month_from_name(" | 
| 48 | 
            -
                #   month_from_name(" | 
| 47 | 
            +
                #   month_from_name("january") # => 1
         | 
| 48 | 
            +
                #   month_from_name("jan")     # => 1
         | 
| 49 49 | 
             
                def month_from_name(month)
         | 
| 50 | 
            -
                   | 
| 50 | 
            +
                  f = lambda {|months| months.compact.map {|x| x.downcase }.index(month) }
         | 
| 51 51 |  | 
| 52 | 
            -
                   | 
| 53 | 
            -
                   | 
| 52 | 
            +
                  month = f[Date::MONTHNAMES] || f[Date::ABBR_MONTHNAMES]
         | 
| 53 | 
            +
                  month ? month + 1 : nil
         | 
| 54 54 | 
             
                end
         | 
| 55 55 |  | 
| 56 56 | 
             
                # Parse "Today", "Tomorrow" and "Yesterday"
         | 
| 57 57 | 
             
                def parse_nearby_days(string, today)
         | 
| 58 | 
            -
                  return today | 
| 59 | 
            -
                  return today - 1 | 
| 60 | 
            -
                  return today + 1 | 
| 58 | 
            +
                  return today     if string == 'today'
         | 
| 59 | 
            +
                  return today - 1 if string == 'yesterday'
         | 
| 60 | 
            +
                  return today + 1 if string == 'tomorrow'
         | 
| 61 61 | 
             
                end
         | 
| 62 62 |  | 
| 63 63 | 
             
                # Parse "Last Monday", "This Monday"
         | 
| @@ -66,7 +66,7 @@ class Kronic | |
| 66 66 |  | 
| 67 67 | 
             
                  if %w(last this).include?(tokens[0])
         | 
| 68 68 | 
             
                    days = (1..7).map {|x| 
         | 
| 69 | 
            -
                      today + (tokens[0] == 'last' ? -x | 
| 69 | 
            +
                      today + (tokens[0] == 'last' ? -x : x)
         | 
| 70 70 | 
             
                    }.inject({}) {|a, x| 
         | 
| 71 71 | 
             
                      a.update(x.strftime("%A").downcase => x) 
         | 
| 72 72 | 
             
                    }
         | 
| @@ -91,7 +91,7 @@ class Kronic | |
| 91 91 | 
             
                    return nil unless day && month && year
         | 
| 92 92 |  | 
| 93 93 | 
             
                    result = Date.new(year, month, day)
         | 
| 94 | 
            -
                    result  | 
| 94 | 
            +
                    result = result << 12 if result > today && !tokens[2]
         | 
| 95 95 | 
             
                    result
         | 
| 96 96 | 
             
                  end
         | 
| 97 97 | 
             
                end
         | 
    
        data/spec/kronic_spec.rb
    CHANGED
    
    | @@ -19,7 +19,8 @@ describe Kronic do | |
| 19 19 | 
             
                  :last_monday => Date.new(2010, 9, 13),
         | 
| 20 20 | 
             
                  :next_monday => Date.new(2010, 9, 20),
         | 
| 21 21 | 
             
                  :sep_4  => Date.new(2010, 9, 4),
         | 
| 22 | 
            -
                  :sep_20 => Date.new(2009, 9, 20)
         | 
| 22 | 
            +
                  :sep_20 => Date.new(2009, 9, 20),
         | 
| 23 | 
            +
                  :sep_28 => Date.new(2010, 9, 28)
         | 
| 23 24 | 
             
                }.fetch(key)
         | 
| 24 25 | 
             
              end
         | 
| 25 26 |  | 
| @@ -31,14 +32,15 @@ describe Kronic do | |
| 31 32 | 
             
              should_parse(:today,        date(:today))
         | 
| 32 33 | 
             
              should_parse('today',       date(:today))
         | 
| 33 34 | 
             
              should_parse('  Today',     date(:today))
         | 
| 34 | 
            -
              should_parse('Yesterday',   date(:today) - 1 | 
| 35 | 
            -
              should_parse('Tomorrow',    date(:today) + 1 | 
| 35 | 
            +
              should_parse('Yesterday',   date(:today) - 1)
         | 
| 36 | 
            +
              should_parse('Tomorrow',    date(:today) + 1)
         | 
| 36 37 | 
             
              should_parse('Last Monday', date(:last_monday))
         | 
| 37 38 | 
             
              should_parse('This Monday', date(:next_monday))
         | 
| 38 39 | 
             
              should_parse('4 Sep',       date(:sep_4))
         | 
| 39 40 | 
             
              should_parse('4  Sep',      date(:sep_4))
         | 
| 40 41 | 
             
              should_parse('4 September', date(:sep_4))
         | 
| 41 42 | 
             
              should_parse('20 Sep',      date(:sep_20))
         | 
| 43 | 
            +
              should_parse('28 Sep 2010', date(:sep_28))
         | 
| 42 44 | 
             
              should_parse('14 Sep 2008', Date.new(2008, 9, 14))
         | 
| 43 45 | 
             
              should_parse('bogus',       nil)
         | 
| 44 46 | 
             
              should_parse('14',          nil)
         | 
| @@ -46,8 +48,8 @@ describe Kronic do | |
| 46 48 | 
             
              should_parse('14 June oen', nil)
         | 
| 47 49 |  | 
| 48 50 | 
             
              should_format('Today',       date(:today))
         | 
| 49 | 
            -
              should_format('Yesterday',   date(:today) - 1 | 
| 50 | 
            -
              should_format('Tomorrow',    date(:today) + 1 | 
| 51 | 
            +
              should_format('Yesterday',   date(:today) - 1)
         | 
| 52 | 
            +
              should_format('Tomorrow',    date(:today) + 1)
         | 
| 51 53 | 
             
              should_format('Last Monday', date(:last_monday))
         | 
| 52 54 | 
             
              should_format('This Monday', date(:next_monday))
         | 
| 53 55 | 
             
              should_format('14 September 2008', Date.new(2008, 9, 14))
         | 
    
        metadata
    CHANGED
    
    | @@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version | |
| 5 5 | 
             
              segments: 
         | 
| 6 6 | 
             
              - 0
         | 
| 7 7 | 
             
              - 2
         | 
| 8 | 
            -
              -  | 
| 9 | 
            -
              version: 0.2. | 
| 8 | 
            +
              - 1
         | 
| 9 | 
            +
              version: 0.2.1
         | 
| 10 10 | 
             
            platform: ruby
         | 
| 11 11 | 
             
            authors: 
         | 
| 12 12 | 
             
            - Xavier Shay
         | 
| @@ -17,36 +17,10 @@ cert_chain: [] | |
| 17 17 | 
             
            date: 2010-09-20 00:00:00 +01:00
         | 
| 18 18 | 
             
            default_executable: 
         | 
| 19 19 | 
             
            dependencies: 
         | 
| 20 | 
            -
            - !ruby/object:Gem::Dependency 
         | 
| 21 | 
            -
              name: activesupport
         | 
| 22 | 
            -
              prerelease: false
         | 
| 23 | 
            -
              requirement: &id001 !ruby/object:Gem::Requirement 
         | 
| 24 | 
            -
                none: false
         | 
| 25 | 
            -
                requirements: 
         | 
| 26 | 
            -
                - - ">="
         | 
| 27 | 
            -
                  - !ruby/object:Gem::Version 
         | 
| 28 | 
            -
                    segments: 
         | 
| 29 | 
            -
                    - 0
         | 
| 30 | 
            -
                    version: "0"
         | 
| 31 | 
            -
              type: :runtime
         | 
| 32 | 
            -
              version_requirements: *id001
         | 
| 33 | 
            -
            - !ruby/object:Gem::Dependency 
         | 
| 34 | 
            -
              name: i18n
         | 
| 35 | 
            -
              prerelease: false
         | 
| 36 | 
            -
              requirement: &id002 !ruby/object:Gem::Requirement 
         | 
| 37 | 
            -
                none: false
         | 
| 38 | 
            -
                requirements: 
         | 
| 39 | 
            -
                - - ">="
         | 
| 40 | 
            -
                  - !ruby/object:Gem::Version 
         | 
| 41 | 
            -
                    segments: 
         | 
| 42 | 
            -
                    - 0
         | 
| 43 | 
            -
                    version: "0"
         | 
| 44 | 
            -
              type: :runtime
         | 
| 45 | 
            -
              version_requirements: *id002
         | 
| 46 20 | 
             
            - !ruby/object:Gem::Dependency 
         | 
| 47 21 | 
             
              name: rspec
         | 
| 48 22 | 
             
              prerelease: false
         | 
| 49 | 
            -
              requirement: & | 
| 23 | 
            +
              requirement: &id001 !ruby/object:Gem::Requirement 
         | 
| 50 24 | 
             
                none: false
         | 
| 51 25 | 
             
                requirements: 
         | 
| 52 26 | 
             
                - - ">="
         | 
| @@ -59,11 +33,11 @@ dependencies: | |
| 59 33 | 
             
                    - 16
         | 
| 60 34 | 
             
                    version: 2.0.0.beta.16
         | 
| 61 35 | 
             
              type: :development
         | 
| 62 | 
            -
              version_requirements: * | 
| 36 | 
            +
              version_requirements: *id001
         | 
| 63 37 | 
             
            - !ruby/object:Gem::Dependency 
         | 
| 64 38 | 
             
              name: timecop
         | 
| 65 39 | 
             
              prerelease: false
         | 
| 66 | 
            -
              requirement: & | 
| 40 | 
            +
              requirement: &id002 !ruby/object:Gem::Requirement 
         | 
| 67 41 | 
             
                none: false
         | 
| 68 42 | 
             
                requirements: 
         | 
| 69 43 | 
             
                - - ">="
         | 
| @@ -72,7 +46,7 @@ dependencies: | |
| 72 46 | 
             
                    - 0
         | 
| 73 47 | 
             
                    version: "0"
         | 
| 74 48 | 
             
              type: :development
         | 
| 75 | 
            -
              version_requirements: * | 
| 49 | 
            +
              version_requirements: *id002
         | 
| 76 50 | 
             
            description: 
         | 
| 77 51 | 
             
            email: 
         | 
| 78 52 | 
             
            - hello@xaviershay.com
         |