date_format 0.0.1 → 0.1.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.
- checksums.yaml +7 -0
- data/Gemfile +5 -4
- data/README.md +50 -50
- data/Rakefile +2 -2
- data/lib/date_format.rb +3 -2
- data/lib/date_format/TestFile.txt +126 -0
- data/lib/date_format/base.rb +131 -48
- data/lib/date_format/version.rb +3 -3
- metadata +10 -14
    
        checksums.yaml
    ADDED
    
    | @@ -0,0 +1,7 @@ | |
| 1 | 
            +
            ---
         | 
| 2 | 
            +
            SHA1:
         | 
| 3 | 
            +
              metadata.gz: 6019ed599e013f624132289a61850cf11c74119b
         | 
| 4 | 
            +
              data.tar.gz: a83df32f68c09749864e671458fbac4a790d2bb4
         | 
| 5 | 
            +
            SHA512:
         | 
| 6 | 
            +
              metadata.gz: 49558b9bc97e84fa848d493f74e58a869e58fcb2f5d97c66b49256ccf1a235c64ca670f3778ea65824ec676474517e3196cfa9528ac163b64b05ba35d97948ff
         | 
| 7 | 
            +
              data.tar.gz: 682bd66a4c32fdff2cb7212cc3acc6baff6271b66e6e2640324e13cc9a514504c5728870dda1312281eaf9f8d96aed05a9b6b7d258a2598cf2e752ee685b62a6
         | 
    
        data/Gemfile
    CHANGED
    
    | @@ -1,4 +1,5 @@ | |
| 1 | 
            -
            source ' | 
| 2 | 
            -
             | 
| 3 | 
            -
            # Specify your gem's dependencies in date_format.gemspec
         | 
| 4 | 
            -
            gemspec
         | 
| 1 | 
            +
            source 'http://rubygems.org'
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            # Specify your gem's dependencies in date_format.gemspec
         | 
| 4 | 
            +
            #gemspec
         | 
| 5 | 
            +
            gem 'rubygems-update'
         | 
    
        data/README.md
    CHANGED
    
    | @@ -1,50 +1,50 @@ | |
| 1 | 
            -
            # DateFormat
         | 
| 2 | 
            -
             | 
| 3 | 
            -
            DateFormat is the gem used to access formatted datetime.
         | 
| 4 | 
            -
             | 
| 5 | 
            -
            ## Installation
         | 
| 6 | 
            -
             | 
| 7 | 
            -
            Add this line to your application's Gemfile:
         | 
| 8 | 
            -
             | 
| 9 | 
            -
                gem 'date_format'
         | 
| 10 | 
            -
             | 
| 11 | 
            -
            And then execute:
         | 
| 12 | 
            -
             | 
| 13 | 
            -
                $ bundle
         | 
| 14 | 
            -
             | 
| 15 | 
            -
            Or install it yourself as:
         | 
| 16 | 
            -
             | 
| 17 | 
            -
                $ gem install date_format
         | 
| 18 | 
            -
             | 
| 19 | 
            -
            ## Usage
         | 
| 20 | 
            -
             | 
| 21 | 
            -
            Try this snippet of code on ruby  | 
| 22 | 
            -
             | 
| 23 | 
            -
                require 'date_format'
         | 
| 24 | 
            -
                today_time = Time.now
         | 
| 25 | 
            -
                puts DateFormat.change_to(today_time, "GENERAL_DATE")                       # => 05/15/14 01:22:29 PM               
         | 
| 26 | 
            -
                puts DateFormat.change_to(today_time, "LONG_DATE")                          # => Thursday, May 15, 2014
         | 
| 27 | 
            -
                puts DateFormat.change_to(today_time, "ISO_8601_FORMAT")                    # => 2014-05-15
         | 
| 28 | 
            -
             | 
| 29 | 
            -
                puts DateFormat.change_to(today_time, "MEDIUM_DATE")                        # => 15-May-2014
         | 
| 30 | 
            -
                puts DateFormat.change_to(today_time, "SHORT_DATE")                         # => 05/15/14
         | 
| 31 | 
            -
                puts DateFormat.change_to(today_time, "LONG_TIME")                          # => 01:22:29 PM
         | 
| 32 | 
            -
                puts DateFormat.change_to(today_time, "MEDIUM_TIME")                        # => 13:22 PM
         | 
| 33 | 
            -
                puts DateFormat.change_to(today_time, "SHORT_TIME")                         # => 13:22
         | 
| 34 | 
            -
                puts DateFormat.change_to(today_time, "WEEK_OF_YEAR")                       # => 19
         | 
| 35 | 
            -
                puts DateFormat.change_to(today_time, "DAY_IN_MONTH")                       # => 15
         | 
| 36 | 
            -
                puts DateFormat.change_to(today_time, "JULIAN_DAY")                         # => 2014
         | 
| 37 | 
            -
                puts DateFormat.change_to(today_time, "ONLY_HOUR_IN_24HOUR_FORMAT")         # => 13 Hour
         | 
| 38 | 
            -
                puts DateFormat.change_to(today_time, "HOURS_IN_24HOUR_FORMAT")             # => 13:34 Hour:Minute
         | 
| 39 | 
            -
                puts DateFormat.change_to(today_time, "MINUTE_IN_HOUR")                     # => 34 Minute
         | 
| 40 | 
            -
             | 
| 41 | 
            -
                puts DateFormat.change_to(today_time, "")
         | 
| 42 | 
            -
                puts DateFormat.change_to("", "")
         | 
| 43 | 
            -
             | 
| 44 | 
            -
            ## Contributing
         | 
| 45 | 
            -
             | 
| 46 | 
            -
            1. Fork it ( https://github.com/[my-github-username]/date_format/fork )
         | 
| 47 | 
            -
            2. Create your feature branch (`git checkout -b my-new-feature`)
         | 
| 48 | 
            -
            3. Commit your changes (`git commit -am 'Add some feature'`)
         | 
| 49 | 
            -
            4. Push to the branch (`git push origin my-new-feature`)
         | 
| 50 | 
            -
            5. Create a new Pull Request
         | 
| 1 | 
            +
            # DateFormat
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            DateFormat is the gem used to access formatted datetime.
         | 
| 4 | 
            +
             | 
| 5 | 
            +
            ## Installation
         | 
| 6 | 
            +
             | 
| 7 | 
            +
            Add this line to your application's Gemfile:
         | 
| 8 | 
            +
             | 
| 9 | 
            +
                gem 'date_format'
         | 
| 10 | 
            +
             | 
| 11 | 
            +
            And then execute:
         | 
| 12 | 
            +
             | 
| 13 | 
            +
                $ bundle
         | 
| 14 | 
            +
             | 
| 15 | 
            +
            Or install it yourself as:
         | 
| 16 | 
            +
             | 
| 17 | 
            +
                $ gem install date_format
         | 
| 18 | 
            +
             | 
| 19 | 
            +
            ## Usage
         | 
| 20 | 
            +
             | 
| 21 | 
            +
            Try this snippet of code on ruby irb
         | 
| 22 | 
            +
             | 
| 23 | 
            +
                require 'date_format'
         | 
| 24 | 
            +
                today_time = Time.now
         | 
| 25 | 
            +
                puts DateFormat.change_to(today_time, "GENERAL_DATE")                       # => 05/15/14 01:22:29 PM               
         | 
| 26 | 
            +
                puts DateFormat.change_to(today_time, "LONG_DATE")                          # => Thursday, May 15, 2014
         | 
| 27 | 
            +
                puts DateFormat.change_to(today_time, "ISO_8601_FORMAT")                    # => 2014-05-15
         | 
| 28 | 
            +
             | 
| 29 | 
            +
                puts DateFormat.change_to(today_time, "MEDIUM_DATE")                        # => 15-May-2014
         | 
| 30 | 
            +
                puts DateFormat.change_to(today_time, "SHORT_DATE")                         # => 05/15/14
         | 
| 31 | 
            +
                puts DateFormat.change_to(today_time, "LONG_TIME")                          # => 01:22:29 PM
         | 
| 32 | 
            +
                puts DateFormat.change_to(today_time, "MEDIUM_TIME")                        # => 13:22 PM
         | 
| 33 | 
            +
                puts DateFormat.change_to(today_time, "SHORT_TIME")                         # => 13:22
         | 
| 34 | 
            +
                puts DateFormat.change_to(today_time, "WEEK_OF_YEAR")                       # => 19
         | 
| 35 | 
            +
                puts DateFormat.change_to(today_time, "DAY_IN_MONTH")                       # => 15
         | 
| 36 | 
            +
                puts DateFormat.change_to(today_time, "JULIAN_DAY")                         # => 2014
         | 
| 37 | 
            +
                puts DateFormat.change_to(today_time, "ONLY_HOUR_IN_24HOUR_FORMAT")         # => 13 Hour
         | 
| 38 | 
            +
                puts DateFormat.change_to(today_time, "HOURS_IN_24HOUR_FORMAT")             # => 13:34 Hour:Minute
         | 
| 39 | 
            +
                puts DateFormat.change_to(today_time, "MINUTE_IN_HOUR")                     # => 34 Minute
         | 
| 40 | 
            +
             | 
| 41 | 
            +
                puts DateFormat.change_to(today_time, "")
         | 
| 42 | 
            +
                puts DateFormat.change_to("", "")
         | 
| 43 | 
            +
             | 
| 44 | 
            +
            ## Contributing
         | 
| 45 | 
            +
             | 
| 46 | 
            +
            1. Fork it ( https://github.com/[my-github-username]/date_format/fork )
         | 
| 47 | 
            +
            2. Create your feature branch (`git checkout -b my-new-feature`)
         | 
| 48 | 
            +
            3. Commit your changes (`git commit -am 'Add some feature'`)
         | 
| 49 | 
            +
            4. Push to the branch (`git push origin my-new-feature`)
         | 
| 50 | 
            +
            5. Create a new Pull Request
         | 
    
        data/Rakefile
    CHANGED
    
    | @@ -1,2 +1,2 @@ | |
| 1 | 
            -
            require "bundler/gem_tasks"
         | 
| 2 | 
            -
             | 
| 1 | 
            +
            require "bundler/gem_tasks"
         | 
| 2 | 
            +
             | 
    
        data/lib/date_format.rb
    CHANGED
    
    | @@ -1,2 +1,3 @@ | |
| 1 | 
            -
            require_relative './date_format/base.rb'
         | 
| 2 | 
            -
            require_relative './date_format/version.rb'
         | 
| 1 | 
            +
            require_relative './date_format/base.rb'
         | 
| 2 | 
            +
            require_relative './date_format/version.rb'
         | 
| 3 | 
            +
            require 'time'
         | 
| @@ -0,0 +1,126 @@ | |
| 1 | 
            +
              def duration(timenow, )
         | 
| 2 | 
            +
                secs  = timenow.to_i
         | 
| 3 | 
            +
                mins  = secs / 60
         | 
| 4 | 
            +
                hours = mins / 60
         | 
| 5 | 
            +
                days  = hours / 24
         | 
| 6 | 
            +
             | 
| 7 | 
            +
                
         | 
| 8 | 
            +
             | 
| 9 | 
            +
                if days > 0
         | 
| 10 | 
            +
                  "#{days} days and #{hours % 24} hours"
         | 
| 11 | 
            +
                elsif hours > 0
         | 
| 12 | 
            +
                  "#{hours} hours and #{mins % 60} minutes"
         | 
| 13 | 
            +
                elsif mins > 0
         | 
| 14 | 
            +
                  "#{mins} minutes and #{secs % 60} seconds"
         | 
| 15 | 
            +
                elsif secs >= 0
         | 
| 16 | 
            +
                  "#{secs} seconds"
         | 
| 17 | 
            +
                end
         | 
| 18 | 
            +
            end
         | 
| 19 | 
            +
             | 
| 20 | 
            +
            def day_difference(start_date, end_date)
         | 
| 21 | 
            +
                end_date = Time.now if end_date == 'PRESENT_DAY'
         | 
| 22 | 
            +
                puts "END Date = #{end_date}"
         | 
| 23 | 
            +
                difference = (end_date - start_date).to_i
         | 
| 24 | 
            +
                puts "difference = #{difference}"
         | 
| 25 | 
            +
                seconds = difference / 60
         | 
| 26 | 
            +
                minutes = seconds / 60
         | 
| 27 | 
            +
                hours = minutes / 60
         | 
| 28 | 
            +
                days = hours / 24
         | 
| 29 | 
            +
                puts "Days : #{days}, Hours : #{hours}, Minutes : #{minutes}, Seconds : #{seconds}"
         | 
| 30 | 
            +
                output = ""
         | 
| 31 | 
            +
                output += "#{days} days" if days > 0
         | 
| 32 | 
            +
                puts "Output1 : #{output}"
         | 
| 33 | 
            +
                output += "#{hours % 24} hours" if hours > 0
         | 
| 34 | 
            +
                puts "Output2 : #{output}"
         | 
| 35 | 
            +
                output += "#{minutes % 60} minutes" if minutes > 0
         | 
| 36 | 
            +
                puts "Output3 : #{output}"
         | 
| 37 | 
            +
                output += "#{seconds % 60} seconds" if seconds > 0
         | 
| 38 | 
            +
                puts "Output4 : #{output}"
         | 
| 39 | 
            +
             | 
| 40 | 
            +
                puts output    
         | 
| 41 | 
            +
            end
         | 
| 42 | 
            +
             | 
| 43 | 
            +
             | 
| 44 | 
            +
             | 
| 45 | 
            +
             | 
| 46 | 
            +
             | 
| 47 | 
            +
             | 
| 48 | 
            +
            def self.day_difference(start_date, PRESENT_DAY)
         | 
| 49 | 
            +
            def self.day_difference(start_date, PRESENT_DAY)
         | 
| 50 | 
            +
             | 
| 51 | 
            +
            def time_difference(start_date, end_time, '') // CompleteDateTime
         | 
| 52 | 
            +
            def time_difference(start_date, end_time, 'ONLY_DAY')
         | 
| 53 | 
            +
            def time_difference(start_date, end_time, 'ONLY_HOURS')
         | 
| 54 | 
            +
             | 
| 55 | 
            +
             | 
| 56 | 
            +
             | 
| 57 | 
            +
             | 
| 58 | 
            +
            //def time_difference(start_date, end_time, 'ONLY_MINUTES')
         | 
| 59 | 
            +
            //def time_difference(start_date, end_time, 'ONLY_SECONDS')
         | 
| 60 | 
            +
             | 
| 61 | 
            +
            def day_difference(start_date, end_date)
         | 
| 62 | 
            +
                end_date = Time.now if end_date == 'PRESENT_DAY'
         | 
| 63 | 
            +
                puts "END Date = #{end_date}"
         | 
| 64 | 
            +
                difference = (end_date - start_date).to_i
         | 
| 65 | 
            +
                puts "difference = #{difference}"
         | 
| 66 | 
            +
                days = 0
         | 
| 67 | 
            +
                hours = difference/3600
         | 
| 68 | 
            +
                minutes = (difference/60)%60
         | 
| 69 | 
            +
                seconds = difference%60
         | 
| 70 | 
            +
                puts "Days : #{days}, Hours : #{hours}, Minutes : #{minutes}, Seconds : #{seconds}"
         | 
| 71 | 
            +
                output = ""
         | 
| 72 | 
            +
                output += "#{days} days" if days > 0
         | 
| 73 | 
            +
                puts "Output1 : #{output}"
         | 
| 74 | 
            +
                output += "#{hours % 24} hours" if hours > 0
         | 
| 75 | 
            +
                puts "Output2 : #{output}"
         | 
| 76 | 
            +
                output += "#{minutes % 60} minutes" if minutes > 0
         | 
| 77 | 
            +
                puts "Output3 : #{output}"
         | 
| 78 | 
            +
                output += "#{seconds % 60} seconds" if seconds > 0
         | 
| 79 | 
            +
                puts "Output4 : #{output}"
         | 
| 80 | 
            +
                puts output    
         | 
| 81 | 
            +
            end
         | 
| 82 | 
            +
             | 
| 83 | 
            +
             | 
| 84 | 
            +
                  rest, secs = self.divmod( 60 )
         | 
| 85 | 
            +
                  rest, mins = rest.divmod( 60 )
         | 
| 86 | 
            +
                  days, hours = rest.divmod( 24 )
         | 
| 87 | 
            +
                  [days, hours, mins, secs]
         | 
| 88 | 
            +
             | 
| 89 | 
            +
            require 'time'
         | 
| 90 | 
            +
            def day_difference(start_date, end_date)
         | 
| 91 | 
            +
                end_date = Time.now if end_date == 'PRESENT_DAY'
         | 
| 92 | 
            +
                time_difference_in_second = (end_date - start_date).to_i
         | 
| 93 | 
            +
                rest, seconds = time_difference_in_second.divmod( 60 )
         | 
| 94 | 
            +
                rest, minutes = rest.divmod( 60 )
         | 
| 95 | 
            +
                days, hours = rest.divmod( 24 )    
         | 
| 96 | 
            +
                output = ""
         | 
| 97 | 
            +
                output += "#{days} days" if days > 0
         | 
| 98 | 
            +
                output += "#{hours} hours" if hours > 0
         | 
| 99 | 
            +
                output += "#{minutes} minutes" if minutes > 0
         | 
| 100 | 
            +
                output += "#{seconds} seconds" if seconds > 0
         | 
| 101 | 
            +
                puts output    
         | 
| 102 | 
            +
            end
         | 
| 103 | 
            +
             | 
| 104 | 
            +
             | 
| 105 | 
            +
            require 'date_format'
         | 
| 106 | 
            +
            start_date = Time.parse('2014-05-25 18:37:11')
         | 
| 107 | 
            +
            DateFormat.time_difference(start_date, "PRESENT_DAY", "DAY_ONLY")
         | 
| 108 | 
            +
            DateFormat.time_difference(start_date, "PRESENT_DAY", "HOUR_ONLY")
         | 
| 109 | 
            +
            DateFormat.time_difference(start_date, "PRESENT_DAY", "MINUTE_ONLY")
         | 
| 110 | 
            +
            DateFormat.time_difference(start_date, "PRESENT_DAY", "SECOND_ONLY")
         | 
| 111 | 
            +
            DateFormat.time_difference(start_date, "", "DAY_ONLY")
         | 
| 112 | 
            +
            DateFormat.time_difference(start_date, "", "HOUR_ONLY")
         | 
| 113 | 
            +
            DateFormat.time_difference(start_date, "", "MINUTE_ONLY")
         | 
| 114 | 
            +
            DateFormat.time_difference(start_date, "", "SECOND_ONLY")
         | 
| 115 | 
            +
            DateFormat.time_difference(start_date, "AA", "DAY_ONLY")
         | 
| 116 | 
            +
            DateFormat.time_difference(start_date, "AA", "HOUR_ONLY")
         | 
| 117 | 
            +
            DateFormat.time_difference(start_date, "XX", "MINUTE_ONLY")
         | 
| 118 | 
            +
            DateFormat.time_difference(start_date, "DD", "SECOND_ONLY")
         | 
| 119 | 
            +
             | 
| 120 | 
            +
            2.0.0-p353 :002 > start_date = Time.parse('2014-05-25 18:37:11')
         | 
| 121 | 
            +
             => 2014-05-25 18:37:11 +0530 
         | 
| 122 | 
            +
            2.0.0-p353 :003 > puts DateFormat.day_difference(start_date, "PRESENT_DAY")
         | 
| 123 | 
            +
             | 
| 124 | 
            +
             | 
| 125 | 
            +
            # FORMAT => DAY_ONLY, HOUR_ONLY, MINUTE_ONLY, SECOND_ONLY
         | 
| 126 | 
            +
              def time_difference(start_date, end_date, format_type)
         | 
    
        data/lib/date_format/base.rb
    CHANGED
    
    | @@ -1,49 +1,132 @@ | |
| 1 | 
            -
            module DateFormat
         | 
| 2 | 
            -
                
         | 
| 3 | 
            -
              def self.change_to(element, format_type)
         | 
| 4 | 
            -
                begin
         | 
| 5 | 
            -
                  unless element.nil? || element == ""
         | 
| 6 | 
            -
                    element.strftime(choose_date_format(format_type))
         | 
| 7 | 
            -
                  else
         | 
| 8 | 
            -
                    "NA"
         | 
| 9 | 
            -
                  end
         | 
| 10 | 
            -
                rescue
         | 
| 11 | 
            -
                  element
         | 
| 12 | 
            -
                end
         | 
| 13 | 
            -
              end
         | 
| 14 | 
            -
                
         | 
| 15 | 
            -
              def self.choose_date_format(format_type)
         | 
| 16 | 
            -
                case format_type      
         | 
| 17 | 
            -
                when "ISO_8601_FORMAT"                              # => 2014-05-15
         | 
| 18 | 
            -
                    "%F"
         | 
| 19 | 
            -
                  when "GENERAL_DATE"                               # => 4/3/93 05:34:00 PM
         | 
| 20 | 
            -
                    "%m/%d/%y %r"
         | 
| 21 | 
            -
                  when "LONG_DATE"                                  # => Saturday, April 3, 2014
         | 
| 22 | 
            -
                    "%A, %B %d, %Y"
         | 
| 23 | 
            -
                  when "MEDIUM_DATE"                                # => 3-Apr-2014
         | 
| 24 | 
            -
                    "%d-%b-%Y"
         | 
| 25 | 
            -
                  when "SHORT_DATE"                                 # => 4/3/93
         | 
| 26 | 
            -
                    "%D"
         | 
| 27 | 
            -
                  when "LONG_TIME"                                  # => 5:34:23 PM
         | 
| 28 | 
            -
                    "%r"
         | 
| 29 | 
            -
                  when "MEDIUM_TIME"                                # => 5:34 PM
         | 
| 30 | 
            -
                    "%H:%M %p"
         | 
| 31 | 
            -
                  when "SHORT_TIME"                                 # => 17:34
         | 
| 32 | 
            -
                    "%H:%M"
         | 
| 33 | 
            -
                  when "WEEK_OF_YEAR"                               # => 19
         | 
| 34 | 
            -
                    "%W"
         | 
| 35 | 
            -
                  when "DAY_IN_MONTH"                               # => 3
         | 
| 36 | 
            -
                    "%d"
         | 
| 37 | 
            -
                  when "JULIAN_DAY"                                 # => 2014
         | 
| 38 | 
            -
                    "%G"
         | 
| 39 | 
            -
                  when "ONLY_HOUR_IN_24HOUR_FORMAT"                 # => 13 Hour
         | 
| 40 | 
            -
                    "%H"
         | 
| 41 | 
            -
                  when "HOURS_IN_24HOUR_FORMAT"                     # => 13:34 Hour:Minute
         | 
| 42 | 
            -
                    "%H:%M"
         | 
| 43 | 
            -
                  when "MINUTE_IN_HOUR"                             # => 34 Minute
         | 
| 44 | 
            -
                    "%M"
         | 
| 45 | 
            -
                  else
         | 
| 46 | 
            -
                    "%d.%m.%y"
         | 
| 47 | 
            -
             | 
| 48 | 
            -
             | 
| 1 | 
            +
            module DateFormat
         | 
| 2 | 
            +
                
         | 
| 3 | 
            +
              def self.change_to(element, format_type)
         | 
| 4 | 
            +
                begin
         | 
| 5 | 
            +
                  unless element.nil? || element == ""
         | 
| 6 | 
            +
                    element.strftime(choose_date_format(format_type))
         | 
| 7 | 
            +
                  else
         | 
| 8 | 
            +
                    "NA"
         | 
| 9 | 
            +
                  end
         | 
| 10 | 
            +
                rescue
         | 
| 11 | 
            +
                  element
         | 
| 12 | 
            +
                end
         | 
| 13 | 
            +
              end
         | 
| 14 | 
            +
                
         | 
| 15 | 
            +
              def self.choose_date_format(format_type)
         | 
| 16 | 
            +
                case format_type      
         | 
| 17 | 
            +
                when "ISO_8601_FORMAT"                              # => 2014-05-15
         | 
| 18 | 
            +
                    "%F"
         | 
| 19 | 
            +
                  when "GENERAL_DATE"                               # => 4/3/93 05:34:00 PM
         | 
| 20 | 
            +
                    "%m/%d/%y %r"
         | 
| 21 | 
            +
                  when "LONG_DATE"                                  # => Saturday, April 3, 2014
         | 
| 22 | 
            +
                    "%A, %B %d, %Y"
         | 
| 23 | 
            +
                  when "MEDIUM_DATE"                                # => 3-Apr-2014
         | 
| 24 | 
            +
                    "%d-%b-%Y"
         | 
| 25 | 
            +
                  when "SHORT_DATE"                                 # => 4/3/93
         | 
| 26 | 
            +
                    "%D"
         | 
| 27 | 
            +
                  when "LONG_TIME"                                  # => 5:34:23 PM
         | 
| 28 | 
            +
                    "%r"
         | 
| 29 | 
            +
                  when "MEDIUM_TIME"                                # => 5:34 PM
         | 
| 30 | 
            +
                    "%H:%M %p"
         | 
| 31 | 
            +
                  when "SHORT_TIME"                                 # => 17:34
         | 
| 32 | 
            +
                    "%H:%M"
         | 
| 33 | 
            +
                  when "WEEK_OF_YEAR"                               # => 19
         | 
| 34 | 
            +
                    "%W"
         | 
| 35 | 
            +
                  when "DAY_IN_MONTH"                               # => 3
         | 
| 36 | 
            +
                    "%d"
         | 
| 37 | 
            +
                  when "JULIAN_DAY"                                 # => 2014
         | 
| 38 | 
            +
                    "%G"
         | 
| 39 | 
            +
                  when "ONLY_HOUR_IN_24HOUR_FORMAT"                 # => 13 Hour
         | 
| 40 | 
            +
                    "%H"
         | 
| 41 | 
            +
                  when "HOURS_IN_24HOUR_FORMAT"                     # => 13:34 Hour:Minute
         | 
| 42 | 
            +
                    "%H:%M"
         | 
| 43 | 
            +
                  when "MINUTE_IN_HOUR"                             # => 34 Minute
         | 
| 44 | 
            +
                    "%M"
         | 
| 45 | 
            +
                  else
         | 
| 46 | 
            +
                    "%d.%m.%y"
         | 
| 47 | 
            +
                end
         | 
| 48 | 
            +
              end
         | 
| 49 | 
            +
              
         | 
| 50 | 
            +
              # FORMAT => DAY_ONLY, HOUR_ONLY, MINUTE_ONLY, SECOND_ONLY
         | 
| 51 | 
            +
              def self.time_difference(start_date, end_date, format_type)
         | 
| 52 | 
            +
                begin
         | 
| 53 | 
            +
                  begin
         | 
| 54 | 
            +
                    end_date = Time.now if end_date == 'PRESENT_DAY' || end_date == ''
         | 
| 55 | 
            +
                    time_difference_in_second = (end_date - start_date).to_i
         | 
| 56 | 
            +
                  rescue
         | 
| 57 | 
            +
                    time_difference_in_second = (Time.now - start_date).to_i
         | 
| 58 | 
            +
                  end
         | 
| 59 | 
            +
             | 
| 60 | 
            +
                  rest, seconds = time_difference_in_second.divmod( 60 )
         | 
| 61 | 
            +
                  rest, minutes = rest.divmod( 60 )
         | 
| 62 | 
            +
                  days, hours = rest.divmod( 24 )
         | 
| 63 | 
            +
             | 
| 64 | 
            +
                  choose_time_difference_format(time_difference_in_second, days, hours, minutes, seconds, format_type)
         | 
| 65 | 
            +
                rescue
         | 
| 66 | 
            +
                  "DATE - Wrong Format"
         | 
| 67 | 
            +
                end
         | 
| 68 | 
            +
                  
         | 
| 69 | 
            +
              end
         | 
| 70 | 
            +
              
         | 
| 71 | 
            +
              def self.choose_time_difference_format(time_difference_in_second, days, hours, minutes, seconds, format_type)
         | 
| 72 | 
            +
                case format_type      
         | 
| 73 | 
            +
                  
         | 
| 74 | 
            +
                  when "DAY_ONLY"
         | 
| 75 | 
            +
                    "#{days} Days"
         | 
| 76 | 
            +
                  
         | 
| 77 | 
            +
                  when "HOUR_ONLY"
         | 
| 78 | 
            +
                    begin
         | 
| 79 | 
            +
                      only_hours = (time_difference_in_second/3600).round(2)
         | 
| 80 | 
            +
                    rescue
         | 
| 81 | 
            +
                      only_hours = (time_difference_in_second/3600)
         | 
| 82 | 
            +
                    end
         | 
| 83 | 
            +
                    "#{only_hours} Hrs"
         | 
| 84 | 
            +
                    
         | 
| 85 | 
            +
                  when "MINUTE_ONLY"
         | 
| 86 | 
            +
                    begin
         | 
| 87 | 
            +
                      only_minutes = (time_difference_in_second/60).round(2)
         | 
| 88 | 
            +
                    rescue
         | 
| 89 | 
            +
                      only_minutes = (time_difference_in_second/60)
         | 
| 90 | 
            +
                    end
         | 
| 91 | 
            +
                    "#{only_minutes} Mins"
         | 
| 92 | 
            +
                    
         | 
| 93 | 
            +
                  when "SECOND_ONLY"
         | 
| 94 | 
            +
                    "#{time_difference_in_second} Seconds"
         | 
| 95 | 
            +
                  else
         | 
| 96 | 
            +
                   "#{days} Days, #{hours} Hours #{minutes} Minutes #{seconds} Seconds" 
         | 
| 97 | 
            +
                end
         | 
| 98 | 
            +
              end
         | 
| 99 | 
            +
              
         | 
| 100 | 
            +
              
         | 
| 101 | 
            +
              def self.day_difference(start_date, end_date)
         | 
| 102 | 
            +
                formatted_time = ""  
         | 
| 103 | 
            +
                end_date = Time.now if end_date == 'PRESENT_DAY'
         | 
| 104 | 
            +
                time_difference_in_second = (end_date - start_date).to_i
         | 
| 105 | 
            +
                rest, seconds = time_difference_in_second.divmod( 60 )
         | 
| 106 | 
            +
                rest, minutes = rest.divmod( 60 )
         | 
| 107 | 
            +
                days, hours = rest.divmod( 24 )    
         | 
| 108 | 
            +
                
         | 
| 109 | 
            +
                if days > 0
         | 
| 110 | 
            +
                  tag = (days < 2) ? "day" : "days"
         | 
| 111 | 
            +
                  formatted_time += "#{days} #{tag} "
         | 
| 112 | 
            +
                end
         | 
| 113 | 
            +
                
         | 
| 114 | 
            +
                if hours > 0
         | 
| 115 | 
            +
                  tag = (hours < 2) ? "hour" : "hours"
         | 
| 116 | 
            +
                  formatted_time += "#{hours} #{tag} "
         | 
| 117 | 
            +
                end
         | 
| 118 | 
            +
                
         | 
| 119 | 
            +
                if minutes > 0
         | 
| 120 | 
            +
                  tag = (minutes < 2) ? "minute" : "minutes"
         | 
| 121 | 
            +
                  formatted_time += "#{minutes} #{tag} "
         | 
| 122 | 
            +
                end
         | 
| 123 | 
            +
             
         | 
| 124 | 
            +
                if seconds > 0
         | 
| 125 | 
            +
                  tag = (seconds < 2) ? "second" : "seconds"
         | 
| 126 | 
            +
                  formatted_time += "#{seconds} #{tag} "
         | 
| 127 | 
            +
                end
         | 
| 128 | 
            +
                  
         | 
| 129 | 
            +
                formatted_time    
         | 
| 130 | 
            +
              end
         | 
| 131 | 
            +
              
         | 
| 49 132 | 
             
            end
         | 
    
        data/lib/date_format/version.rb
    CHANGED
    
    | @@ -1,3 +1,3 @@ | |
| 1 | 
            -
            module DateFormat
         | 
| 2 | 
            -
              VERSION = "0.0 | 
| 3 | 
            -
            end
         | 
| 1 | 
            +
            module DateFormat
         | 
| 2 | 
            +
              VERSION = "0.1.0"
         | 
| 3 | 
            +
            end
         | 
    
        metadata
    CHANGED
    
    | @@ -1,8 +1,7 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: date_format
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0.0 | 
| 5 | 
            -
              prerelease: 
         | 
| 4 | 
            +
              version: 0.1.0
         | 
| 6 5 | 
             
            platform: ruby
         | 
| 7 6 | 
             
            authors:
         | 
| 8 7 | 
             
            - Rahul Patil
         | 
| @@ -14,7 +13,6 @@ dependencies: | |
| 14 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 15 14 | 
             
              name: bundler
         | 
| 16 15 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| 17 | 
            -
                none: false
         | 
| 18 16 | 
             
                requirements:
         | 
| 19 17 | 
             
                - - ~>
         | 
| 20 18 | 
             
                  - !ruby/object:Gem::Version
         | 
| @@ -22,7 +20,6 @@ dependencies: | |
| 22 20 | 
             
              type: :development
         | 
| 23 21 | 
             
              prerelease: false
         | 
| 24 22 | 
             
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 25 | 
            -
                none: false
         | 
| 26 23 | 
             
                requirements:
         | 
| 27 24 | 
             
                - - ~>
         | 
| 28 25 | 
             
                  - !ruby/object:Gem::Version
         | 
| @@ -30,7 +27,6 @@ dependencies: | |
| 30 27 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 31 28 | 
             
              name: rake
         | 
| 32 29 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| 33 | 
            -
                none: false
         | 
| 34 30 | 
             
                requirements:
         | 
| 35 31 | 
             
                - - ~>
         | 
| 36 32 | 
             
                  - !ruby/object:Gem::Version
         | 
| @@ -38,7 +34,6 @@ dependencies: | |
| 38 34 | 
             
              type: :development
         | 
| 39 35 | 
             
              prerelease: false
         | 
| 40 36 | 
             
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 41 | 
            -
                none: false
         | 
| 42 37 | 
             
                requirements:
         | 
| 43 38 | 
             
                - - ~>
         | 
| 44 39 | 
             
                  - !ruby/object:Gem::Version
         | 
| @@ -51,35 +46,36 @@ executables: [] | |
| 51 46 | 
             
            extensions: []
         | 
| 52 47 | 
             
            extra_rdoc_files: []
         | 
| 53 48 | 
             
            files:
         | 
| 54 | 
            -
            - README.md
         | 
| 55 49 | 
             
            - Gemfile
         | 
| 50 | 
            +
            - README.md
         | 
| 56 51 | 
             
            - Rakefile
         | 
| 52 | 
            +
            - lib/date_format.rb
         | 
| 53 | 
            +
            - lib/date_format/TestFile.txt
         | 
| 57 54 | 
             
            - lib/date_format/base.rb
         | 
| 58 55 | 
             
            - lib/date_format/version.rb
         | 
| 59 | 
            -
            - lib/date_format.rb
         | 
| 60 56 | 
             
            homepage: ''
         | 
| 61 57 | 
             
            licenses:
         | 
| 62 58 | 
             
            - MIT
         | 
| 59 | 
            +
            metadata: {}
         | 
| 63 60 | 
             
            post_install_message: 
         | 
| 64 61 | 
             
            rdoc_options: []
         | 
| 65 62 | 
             
            require_paths:
         | 
| 66 63 | 
             
            - lib
         | 
| 67 64 | 
             
            required_ruby_version: !ruby/object:Gem::Requirement
         | 
| 68 | 
            -
              none: false
         | 
| 69 65 | 
             
              requirements:
         | 
| 70 | 
            -
              - -  | 
| 66 | 
            +
              - - '>='
         | 
| 71 67 | 
             
                - !ruby/object:Gem::Version
         | 
| 72 68 | 
             
                  version: '0'
         | 
| 73 69 | 
             
            required_rubygems_version: !ruby/object:Gem::Requirement
         | 
| 74 | 
            -
              none: false
         | 
| 75 70 | 
             
              requirements:
         | 
| 76 | 
            -
              - -  | 
| 71 | 
            +
              - - '>='
         | 
| 77 72 | 
             
                - !ruby/object:Gem::Version
         | 
| 78 73 | 
             
                  version: '0'
         | 
| 79 74 | 
             
            requirements: []
         | 
| 80 75 | 
             
            rubyforge_project: 
         | 
| 81 | 
            -
            rubygems_version:  | 
| 76 | 
            +
            rubygems_version: 2.2.2
         | 
| 82 77 | 
             
            signing_key: 
         | 
| 83 | 
            -
            specification_version:  | 
| 78 | 
            +
            specification_version: 4
         | 
| 84 79 | 
             
            summary: Date Format
         | 
| 85 80 | 
             
            test_files: []
         | 
| 81 | 
            +
            has_rdoc: 
         |