fossil 0.4.26 → 0.5.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/Rakefile +1 -1
- data/VERSION +1 -1
- data/fossil.gemspec +8 -11
- data/lib/date_extentions.rb +26 -0
- data/lib/delegate_method.rb +84 -0
- data/lib/fossil.rb +10 -7
- data/lib/hash_extentions.rb +53 -1
- data/lib/models/trip_leg.rb +12 -8
- data/lib/sequel/fos_dates.rb +46 -14
- data/lib/sequel/metaprogramming.rb +25 -6
- data/lib/sequel/model_patch.rb +3 -3
- data/lib/sequel/pervasive_adapter.rb +1 -1
- data/lib/sequel/serializer/json_serializer.rb +20 -27
- data/lib/sequel/serializer/serializer.rb +9 -9
- data/lib/sequel/serializer/xml_serializer.rb +112 -23
- data/spec/helper_methods.rb +6 -6
- data/spec/models/trip_leg_spec.rb +175 -175
- data/spec/models/vendor_document_spec.rb +1 -0
- data/spec/sequel/fos_dates_spec.rb +7 -3
- data/spec/sequel/model_patch_spec.rb +26 -7
- data/spec/sequel/serializer/json_serializer_spec.rb +3 -0
- data/spec/spec_helper.rb +15 -7
- metadata +13 -22
- data/spec/spec.opts +0 -4
    
        data/Rakefile
    CHANGED
    
    | @@ -10,7 +10,7 @@ | |
| 10 10 | 
             
                 gemspec.email = "plardin@xojet.com"  
         | 
| 11 11 | 
             
                 gemspec.homepage = ""
         | 
| 12 12 | 
             
                 gemspec.add_dependency('sequel', '= 3.13.0')
         | 
| 13 | 
            -
                 gemspec.add_dependency('activesupport', '= 2.3.5')
         | 
| 13 | 
            +
            #     gemspec.add_dependency('activesupport', '= 2.3.5')
         | 
| 14 14 | 
             
                 gemspec.add_development_dependency('rspec')
         | 
| 15 15 | 
             
                 gemspec.authors = ["Patrick Lardin, Daniel Sudol"]
         | 
| 16 16 | 
             
               end
         | 
    
        data/VERSION
    CHANGED
    
    | @@ -1 +1 @@ | |
| 1 | 
            -
            0. | 
| 1 | 
            +
            0.5.0
         | 
    
        data/fossil.gemspec
    CHANGED
    
    | @@ -1,21 +1,23 @@ | |
| 1 1 | 
             
            # Generated by jeweler
         | 
| 2 | 
            -
            # DO NOT EDIT THIS FILE | 
| 3 | 
            -
            # Instead, edit Jeweler::Tasks in Rakefile, and run  | 
| 2 | 
            +
            # DO NOT EDIT THIS FILE
         | 
| 3 | 
            +
            # Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
         | 
| 4 4 | 
             
            # -*- encoding: utf-8 -*-
         | 
| 5 5 |  | 
| 6 6 | 
             
            Gem::Specification.new do |s|
         | 
| 7 7 | 
             
              s.name = %q{fossil}
         | 
| 8 | 
            -
              s.version = "0. | 
| 8 | 
            +
              s.version = "0.5.0"
         | 
| 9 9 |  | 
| 10 10 | 
             
              s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
         | 
| 11 11 | 
             
              s.authors = ["Patrick Lardin, Daniel Sudol"]
         | 
| 12 | 
            -
              s.date = %q{2010- | 
| 12 | 
            +
              s.date = %q{2010-10-04}
         | 
| 13 13 | 
             
              s.description = %q{Access FOS/betrieve db with this Sequel based orm wrapper}
         | 
| 14 14 | 
             
              s.email = %q{plardin@xojet.com}
         | 
| 15 15 | 
             
              s.files = [
         | 
| 16 16 | 
             
                "Rakefile",
         | 
| 17 17 | 
             
                 "VERSION",
         | 
| 18 18 | 
             
                 "fossil.gemspec",
         | 
| 19 | 
            +
                 "lib/date_extentions.rb",
         | 
| 20 | 
            +
                 "lib/delegate_method.rb",
         | 
| 19 21 | 
             
                 "lib/fos_schema/FOS_SCHEMA_3.8.22.r3.csv",
         | 
| 20 22 | 
             
                 "lib/fos_schema/FOS_SCHEMA_3.8.27.r1.csv",
         | 
| 21 23 | 
             
                 "lib/fos_schema/FOS_SCHEMA_3.9.0.csv",
         | 
| @@ -146,13 +148,12 @@ Gem::Specification.new do |s| | |
| 146 148 | 
             
                 "spec/sequel/serializer/json_serializer_spec.rb",
         | 
| 147 149 | 
             
                 "spec/sequel/serializer/xml_serializer_spec.rb",
         | 
| 148 150 | 
             
                 "spec/sequel/spec_helper_tables.rb",
         | 
| 149 | 
            -
                 "spec/spec.opts",
         | 
| 150 151 | 
             
                 "spec/spec_helper.rb"
         | 
| 151 152 | 
             
              ]
         | 
| 152 153 | 
             
              s.homepage = %q{}
         | 
| 153 154 | 
             
              s.rdoc_options = ["--charset=UTF-8"]
         | 
| 154 155 | 
             
              s.require_paths = ["lib"]
         | 
| 155 | 
            -
              s.rubygems_version = %q{1.3. | 
| 156 | 
            +
              s.rubygems_version = %q{1.3.7}
         | 
| 156 157 | 
             
              s.summary = %q{Sequel orm wrapper to FOS}
         | 
| 157 158 | 
             
              s.test_files = [
         | 
| 158 159 | 
             
                "spec/hash_extentions_spec.rb",
         | 
| @@ -180,19 +181,15 @@ Gem::Specification.new do |s| | |
| 180 181 | 
             
                current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
         | 
| 181 182 | 
             
                s.specification_version = 3
         | 
| 182 183 |  | 
| 183 | 
            -
                if Gem::Version.new(Gem:: | 
| 184 | 
            +
                if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
         | 
| 184 185 | 
             
                  s.add_runtime_dependency(%q<sequel>, ["= 3.13.0"])
         | 
| 185 | 
            -
                  s.add_runtime_dependency(%q<activesupport>, ["= 2.3.5"])
         | 
| 186 186 | 
             
                  s.add_development_dependency(%q<rspec>, [">= 0"])
         | 
| 187 187 | 
             
                else
         | 
| 188 188 | 
             
                  s.add_dependency(%q<sequel>, ["= 3.13.0"])
         | 
| 189 | 
            -
                  s.add_dependency(%q<activesupport>, ["= 2.3.5"])
         | 
| 190 189 | 
             
                  s.add_dependency(%q<rspec>, [">= 0"])
         | 
| 191 190 | 
             
                end
         | 
| 192 191 | 
             
              else
         | 
| 193 192 | 
             
                s.add_dependency(%q<sequel>, ["= 3.13.0"])
         | 
| 194 | 
            -
                s.add_dependency(%q<activesupport>, ["= 2.3.5"])
         | 
| 195 193 | 
             
                s.add_dependency(%q<rspec>, [">= 0"])
         | 
| 196 194 | 
             
              end
         | 
| 197 195 | 
             
            end
         | 
| 198 | 
            -
             | 
| @@ -0,0 +1,26 @@ | |
| 1 | 
            +
            p require 'date'
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            class DateTime
         | 
| 4 | 
            +
              # Converts self to a Ruby Date object; time portion is discarded
         | 
| 5 | 
            +
              def to_date
         | 
| 6 | 
            +
                ::Date.new(year, month, day)
         | 
| 7 | 
            +
              end unless method_defined?(:to_date)
         | 
| 8 | 
            +
            end
         | 
| 9 | 
            +
             | 
| 10 | 
            +
             | 
| 11 | 
            +
            class Numeric
         | 
| 12 | 
            +
              def minutes
         | 
| 13 | 
            +
                self * 60
         | 
| 14 | 
            +
              end
         | 
| 15 | 
            +
              alias :minute :minutes
         | 
| 16 | 
            +
             | 
| 17 | 
            +
              def hours
         | 
| 18 | 
            +
                self * 3600
         | 
| 19 | 
            +
              end
         | 
| 20 | 
            +
              alias :hour :hours
         | 
| 21 | 
            +
             | 
| 22 | 
            +
              def days
         | 
| 23 | 
            +
                self * 24.hours
         | 
| 24 | 
            +
              end
         | 
| 25 | 
            +
              alias :day :days
         | 
| 26 | 
            +
            end
         | 
| @@ -0,0 +1,84 @@ | |
| 1 | 
            +
            class Module
         | 
| 2 | 
            +
              #  Patching delegate to take default value as option, which means that instead of
         | 
| 3 | 
            +
              #  returning nil in any situation it will return the default value. So if the
         | 
| 4 | 
            +
              #  object you delegate to does not exist or the method on that object does not exist
         | 
| 5 | 
            +
              #  or the method returns nil then the default value is returned.
         | 
| 6 | 
            +
              #  Note that if you use a default value then the allow nil is automatically set to false,
         | 
| 7 | 
            +
              #  since you will always return the default if there is nil value
         | 
| 8 | 
            +
              #
         | 
| 9 | 
            +
              #  class Invoice < Struct.new(:client)
         | 
| 10 | 
            +
              #    delegate :name, :to => :client, :default => 'Dano'
         | 
| 11 | 
            +
              #  end
         | 
| 12 | 
            +
              #
         | 
| 13 | 
            +
              #  Example 1:
         | 
| 14 | 
            +
              #  invoice = Invoice.new(nil) # no client
         | 
| 15 | 
            +
              #  invoice.client_name    # => "Dano"
         | 
| 16 | 
            +
              #
         | 
| 17 | 
            +
              #  Example 2:
         | 
| 18 | 
            +
              #  Client = Struct.new(:address) # client does not have attribute called name
         | 
| 19 | 
            +
              #  john_doe = Client.new("1 park avenue")
         | 
| 20 | 
            +
              #  invoice = Invoice.new(john_doe)
         | 
| 21 | 
            +
              #  invoice.client_name    # => "Dano"
         | 
| 22 | 
            +
              #
         | 
| 23 | 
            +
              #  Example 3:
         | 
| 24 | 
            +
              #  Client = Struct.new(:name, :address)
         | 
| 25 | 
            +
              #  john_doe = Client.new(nil, "1 park avenue") # client name is nil
         | 
| 26 | 
            +
              #  invoice = Invoice.new(john_doe)
         | 
| 27 | 
            +
              #  invoice.client_name    # => "Dano"
         | 
| 28 | 
            +
              #
         | 
| 29 | 
            +
              #
         | 
| 30 | 
            +
              def delegate(*methods)
         | 
| 31 | 
            +
                options = methods.pop
         | 
| 32 | 
            +
             | 
| 33 | 
            +
                unless options.is_a?(Hash) && to = options[:to]
         | 
| 34 | 
            +
                  raise ArgumentError, "Delegation needs a target. Supply an options hash with a :to key as the last argument (e.g. delegate :hello, :to => :greeter)."
         | 
| 35 | 
            +
                end
         | 
| 36 | 
            +
             | 
| 37 | 
            +
                if options[:prefix] == true && options[:to].to_s =~ /^[^a-z_]/
         | 
| 38 | 
            +
                  raise ArgumentError, "Can only automatically set the delegation prefix when delegating to a method."
         | 
| 39 | 
            +
                end
         | 
| 40 | 
            +
             | 
| 41 | 
            +
                prefix = options[:prefix] && "#{options[:prefix] == true ? to : options[:prefix]}_"
         | 
| 42 | 
            +
             | 
| 43 | 
            +
                default = options[:default]
         | 
| 44 | 
            +
             | 
| 45 | 
            +
                allow_nil = (options[:allow_nil] || default) && "#{to} && "
         | 
| 46 | 
            +
             | 
| 47 | 
            +
                methods.each do |method|
         | 
| 48 | 
            +
             | 
| 49 | 
            +
                  writer(method, to, prefix) if options[:writer]
         | 
| 50 | 
            +
             | 
| 51 | 
            +
                  module_eval(<<-EOS, "(__DELEGATION__)", 1)
         | 
| 52 | 
            +
                      def #{prefix}#{method}(*args, &block)                                   # def customer_name(*args, &block)
         | 
| 53 | 
            +
                        val = #{allow_nil}#{to}.__send__(#{method.inspect}, *args, &block)    #   val = client && client.__send__(:name, *args, &block)
         | 
| 54 | 
            +
                        return "#{default}" if val.nil? and #{!default.blank?}                #   return default if val.nil? and !default.blank?
         | 
| 55 | 
            +
                        val                                                                   #   val
         | 
| 56 | 
            +
                      end                                                                     # end
         | 
| 57 | 
            +
                  EOS
         | 
| 58 | 
            +
                end
         | 
| 59 | 
            +
              end
         | 
| 60 | 
            +
             | 
| 61 | 
            +
              #####################################################################
         | 
| 62 | 
            +
              #  writer :tail_number, :aircraft
         | 
| 63 | 
            +
              #
         | 
| 64 | 
            +
              #  creates a method like this:
         | 
| 65 | 
            +
              #
         | 
| 66 | 
            +
              #  def tail_number=(tail_number)
         | 
| 67 | 
            +
              #    self.aircraft = Aircraft.find_by_tail_number(tail_number)
         | 
| 68 | 
            +
              #  end
         | 
| 69 | 
            +
              #
         | 
| 70 | 
            +
              #  in this case the setter_attribute is the same as the attribute name
         | 
| 71 | 
            +
              #  but in a case like this:
         | 
| 72 | 
            +
              #
         | 
| 73 | 
            +
              #  setter :pic_xojet_id, :pilot, :pic_pilot
         | 
| 74 | 
            +
              #
         | 
| 75 | 
            +
              #  you are saying set the attribue pic_pilot to a pilot
         | 
| 76 | 
            +
              #
         | 
| 77 | 
            +
              def writer(setter_attribute, model, prefix)
         | 
| 78 | 
            +
                define_method "#{prefix}#{setter_attribute.to_s}=" do |value|
         | 
| 79 | 
            +
                  found_model = model.to_s.capitalize.constantize.find(:first, :conditions=> {setter_attribute => value})
         | 
| 80 | 
            +
                  self.send("#{model.to_s}=", found_model)
         | 
| 81 | 
            +
                end
         | 
| 82 | 
            +
              end
         | 
| 83 | 
            +
             | 
| 84 | 
            +
            end
         | 
    
        data/lib/fossil.rb
    CHANGED
    
    | @@ -7,21 +7,24 @@ rescue LoadError => e | |
| 7 7 | 
             
              raise("To use Fossil you need the sequel gem:\n '$ sudo gem install sequel -v=3.13.0'")
         | 
| 8 8 | 
             
            end
         | 
| 9 9 |  | 
| 10 | 
            -
            begin
         | 
| 11 | 
            -
              gem 'activesupport', '=2.3.5'
         | 
| 12 | 
            -
              require('active_support')
         | 
| 13 | 
            -
            rescue LoadError => e
         | 
| 14 | 
            -
               p e.message
         | 
| 15 | 
            -
              raise "To use Fossil you need the active_support gem: '$ sudo gem install active_support -v=2.3.5'"
         | 
| 16 | 
            -
            end
         | 
| 10 | 
            +
            #begin
         | 
| 11 | 
            +
            #  gem 'activesupport', '=2.3.5'
         | 
| 12 | 
            +
            #  require('active_support')
         | 
| 13 | 
            +
            #rescue LoadError => e
         | 
| 14 | 
            +
            #   p e.message
         | 
| 15 | 
            +
            #  raise "To use Fossil you need the active_support gem: '$ sudo gem install active_support -v=2.3.5'"
         | 
| 16 | 
            +
            #end
         | 
| 17 17 |  | 
| 18 18 | 
             
            dir = File.dirname(__FILE__)
         | 
| 19 19 | 
             
            files = [File.join(dir,'number_helper.rb')] +
         | 
| 20 20 | 
             
                    [File.join(dir,'hash_extentions.rb')] +
         | 
| 21 | 
            +
                    [File.join(dir,'date_extentions.rb')] +
         | 
| 22 | 
            +
                    [File.join(dir,'delegate_method.rb')] +
         | 
| 21 23 | 
             
                    [File.join(dir,'sequel','serializer','serializer.rb')] +
         | 
| 22 24 | 
             
                    Dir.glob(File.join(dir,'sequel','*.rb')) +
         | 
| 23 25 | 
             
                    Dir.glob(File.join(dir,'models','*.rb'))
         | 
| 24 26 |  | 
| 27 | 
            +
            Sequel.extension(:blank, :inflector) 
         | 
| 25 28 |  | 
| 26 29 | 
             
            class MockDataset < Sequel::Dataset
         | 
| 27 30 | 
             
              def insert(*args); end
         | 
    
        data/lib/hash_extentions.rb
    CHANGED
    
    | @@ -1,4 +1,28 @@ | |
| 1 | 
            -
             | 
| 1 | 
            +
            require 'json'
         | 
| 2 | 
            +
            class Hash
         | 
| 3 | 
            +
              XML_TYPE_NAMES =
         | 
| 4 | 
            +
                  {
         | 
| 5 | 
            +
                      "Symbol"     => "symbol",
         | 
| 6 | 
            +
                      "Fixnum"     => "integer",
         | 
| 7 | 
            +
                      "Bignum"     => "integer",
         | 
| 8 | 
            +
                      "BigDecimal" => "decimal",
         | 
| 9 | 
            +
                      "Float"      => "float",
         | 
| 10 | 
            +
                      "TrueClass"  => "boolean",
         | 
| 11 | 
            +
                      "FalseClass" => "boolean",
         | 
| 12 | 
            +
                      "Date"       => "date",
         | 
| 13 | 
            +
                      "DateTime"   => "datetime",
         | 
| 14 | 
            +
                      "Time"       => "datetime",
         | 
| 15 | 
            +
                      "ActiveSupport::TimeWithZone" => "datetime"
         | 
| 16 | 
            +
                  }
         | 
| 17 | 
            +
             | 
| 18 | 
            +
              XML_FORMATTING =
         | 
| 19 | 
            +
                  {
         | 
| 20 | 
            +
                      "symbol"   => Proc.new { |symbol| symbol.to_s },
         | 
| 21 | 
            +
                      "date"     => Proc.new { |date| date.strftime('%d/%m/%Y') },
         | 
| 22 | 
            +
                      "datetime" => Proc.new { |time| time.xmlschema },
         | 
| 23 | 
            +
                      "yaml"     => Proc.new { |yaml| yaml.to_yaml }
         | 
| 24 | 
            +
                  }
         | 
| 25 | 
            +
             | 
| 2 26 | 
             
              def limit_to_keys(limit_keys)
         | 
| 3 27 | 
             
                dup.limit_to_keys!(limit_keys)
         | 
| 4 28 | 
             
              end
         | 
| @@ -17,4 +41,32 @@ class Hash | |
| 17 41 | 
             
              def deep_clone
         | 
| 18 42 | 
             
                Marshal::load(Marshal.dump(self))
         | 
| 19 43 | 
             
              end
         | 
| 44 | 
            +
             | 
| 45 | 
            +
              # Return a new hash with all keys converted to strings.
         | 
| 46 | 
            +
              def stringify_keys
         | 
| 47 | 
            +
                dup.stringify_keys!
         | 
| 48 | 
            +
              end
         | 
| 49 | 
            +
             | 
| 50 | 
            +
              # Destructively convert all keys to strings.
         | 
| 51 | 
            +
              def stringify_keys!
         | 
| 52 | 
            +
                keys.each do |key|
         | 
| 53 | 
            +
                  self[key.to_s] = delete(key)
         | 
| 54 | 
            +
                end
         | 
| 55 | 
            +
                self
         | 
| 56 | 
            +
              end
         | 
| 57 | 
            +
             | 
| 58 | 
            +
              # Return a new hash with all keys converted to symbols, as long as
         | 
| 59 | 
            +
              # they respond to +to_sym+.
         | 
| 60 | 
            +
              def symbolize_keys
         | 
| 61 | 
            +
                dup.symbolize_keys!
         | 
| 62 | 
            +
              end
         | 
| 63 | 
            +
             | 
| 64 | 
            +
              # Destructively convert all keys to symbols, as long as they respond
         | 
| 65 | 
            +
              # to +to_sym+.
         | 
| 66 | 
            +
              def symbolize_keys!
         | 
| 67 | 
            +
                keys.each do |key|
         | 
| 68 | 
            +
                  self[(key.to_sym rescue key) || key] = delete(key)
         | 
| 69 | 
            +
                end
         | 
| 70 | 
            +
                self
         | 
| 71 | 
            +
              end
         | 
| 20 72 | 
             
            end
         | 
    
        data/lib/models/trip_leg.rb
    CHANGED
    
    | @@ -663,9 +663,9 @@ class TripLeg < Sequel::Model(:'trip legs') | |
| 663 663 | 
             
              column_def_datetime :actual_departure_date_time_gmt, :'dept date act gmt', :'dept time act gmt'
         | 
| 664 664 |  | 
| 665 665 | 
             
              def actual_takeoff_date_time_gmt
         | 
| 666 | 
            -
                 | 
| 667 | 
            -
                 | 
| 668 | 
            -
                 | 
| 666 | 
            +
                time = t_o_time_act_gmt
         | 
| 667 | 
            +
                time += 60*24 if t_o_time_act_gmt < dept_time_act_gmt
         | 
| 668 | 
            +
                DateTime.from_fos_date_time(dept_date_act_gmt, time)
         | 
| 669 669 | 
             
              end
         | 
| 670 670 |  | 
| 671 671 | 
             
              column_view   :arrival_date_gmt,      :date,  :actual_arrival_date_gmt
         | 
| @@ -673,9 +673,9 @@ class TripLeg < Sequel::Model(:'trip legs') | |
| 673 673 | 
             
              column_def_datetime :actual_arrival_date_time_gmt, :'arrival date gmt', :'arriv time act gmt'
         | 
| 674 674 |  | 
| 675 675 | 
             
              def actual_land_date_time_gmt
         | 
| 676 | 
            -
                 | 
| 677 | 
            -
                 | 
| 678 | 
            -
                 | 
| 676 | 
            +
                time = land_time_act_gmt
         | 
| 677 | 
            +
                time -= 60*24 if land_time_act_gmt > arriv_time_act_gmt
         | 
| 678 | 
            +
                DateTime.from_fos_date_time(arrival_date_gmt, time)
         | 
| 679 679 | 
             
              end
         | 
| 680 680 |  | 
| 681 681 | 
             
              column_view   :dept_date_act_local,   :date,  :actual_departure_date_local
         | 
| @@ -705,12 +705,16 @@ class TripLeg < Sequel::Model(:'trip legs') | |
| 705 705 | 
             
              column_view   :dept_date_act_home,    :date,  :actual_departure_date_base
         | 
| 706 706 | 
             
              column_view   :depart_time_act_home,  :time,  :actual_departure_time_base
         | 
| 707 707 | 
             
              column_def_datetime :actual_departure_date_time_base_old, :'dept date act home', :'depart time act home'
         | 
| 708 | 
            -
              def actual_departure_date_time_base | 
| 708 | 
            +
              def actual_departure_date_time_base
         | 
| 709 | 
            +
                (actual_departure_date_time_gmt.to_time + (home_tz_gmt_offset/10).hours).to_datetime
         | 
| 710 | 
            +
              end
         | 
| 709 711 |  | 
| 710 712 | 
             
              column_view   :arr_date_act_home,     :date,  :actual_arrival_date_base
         | 
| 711 713 | 
             
              column_view   :arrival_time_act_hom,  :time,  :actual_arrival_time_base
         | 
| 712 714 | 
             
              column_def_datetime :actual_arrival_date_time_base_old,   :'arr date act home', :'arrival time act hom'
         | 
| 713 | 
            -
              def actual_arrival_date_time_base | 
| 715 | 
            +
              def actual_arrival_date_time_base
         | 
| 716 | 
            +
                (actual_arrival_date_time_gmt.to_time + (home_tz_gmt_offset/10).hours).to_datetime
         | 
| 717 | 
            +
              end
         | 
| 714 718 |  | 
| 715 719 | 
             
              column_view :ete,                 :time
         | 
| 716 720 | 
             
              column_view :eft,                 :time
         | 
    
        data/lib/sequel/fos_dates.rb
    CHANGED
    
    | @@ -1,6 +1,5 @@ | |
| 1 1 | 
             
            class Date
         | 
| 2 2 | 
             
              FOS_JD_OFFSET_DAYS = Date.parse('1899-12-31').jd
         | 
| 3 | 
            -
              DATE_FORMATS[:mdy] = "%m/%d/%Y"
         | 
| 4 3 |  | 
| 5 4 | 
             
              def self.from_fos_days(days)
         | 
| 6 5 | 
             
                self.jd(FOS_JD_OFFSET_DAYS + days)
         | 
| @@ -9,10 +8,26 @@ class Date | |
| 9 8 | 
             
              def to_fos_days
         | 
| 10 9 | 
             
                jd - FOS_JD_OFFSET_DAYS
         | 
| 11 10 | 
             
              end
         | 
| 11 | 
            +
             | 
| 12 | 
            +
              ######## from Ruby Cookbook #########
         | 
| 13 | 
            +
              def to_gm_time
         | 
| 14 | 
            +
                to_time(new_offset, :gm)
         | 
| 15 | 
            +
              end
         | 
| 16 | 
            +
             | 
| 17 | 
            +
              def to_local_time
         | 
| 18 | 
            +
                to_time(new_offset(DateTime.now.offset-offset), :local)
         | 
| 19 | 
            +
              end
         | 
| 20 | 
            +
             | 
| 21 | 
            +
              private
         | 
| 22 | 
            +
              def to_time(dest, method)
         | 
| 23 | 
            +
                #Convert a fraction of a day to a number of microseconds
         | 
| 24 | 
            +
                usec = (dest.send(:sec_fraction) * 60 * 60 * 24 * (10**6)).to_i
         | 
| 25 | 
            +
                Time.send(method, dest.year, dest.month, dest.day, dest.send(:hour), dest.send(:min),
         | 
| 26 | 
            +
                          dest.send(:sec), usec)
         | 
| 27 | 
            +
              end
         | 
| 12 28 | 
             
            end
         | 
| 13 29 |  | 
| 14 30 | 
             
            module TimeFunctions
         | 
| 15 | 
            -
             | 
| 16 31 | 
             
              def as_minutes
         | 
| 17 32 | 
             
                hour*60 + min
         | 
| 18 33 | 
             
              end
         | 
| @@ -21,7 +36,7 @@ module TimeFunctions | |
| 21 36 | 
             
                return 0 if hour + min == 0
         | 
| 22 37 | 
             
                minutes = hour*60 + min
         | 
| 23 38 | 
             
                val = "#{minutes/60}.#{((100*(minutes.modulo(60)))/60).to_s.rjust(2, '0')}"
         | 
| 24 | 
            -
                BigDecimal.new(val, 2).round(2). | 
| 39 | 
            +
                BigDecimal.new(val, 2).round(2).to_f
         | 
| 25 40 | 
             
              end
         | 
| 26 41 |  | 
| 27 42 | 
             
              # xos is rounding XOJET STYLE, which is a funky copy of how ipc did it
         | 
| @@ -29,7 +44,7 @@ module TimeFunctions | |
| 29 44 | 
             
                return 0 if hour + min == 0
         | 
| 30 45 | 
             
                # It was determined that "ODD" increments of .05 (ie .15, .35, .55, .75, .95) of an hour (ie. 9,21,33,45,57 minutes) rounded UP whereas even increments of .05 rounded DOWN - sn
         | 
| 31 46 | 
             
                minutes = as_minutes
         | 
| 32 | 
            -
                (minutes/60.0 + ([9, 21, 33, 45, 57].include?( | 
| 47 | 
            +
                (minutes/60.0 + ([9, 21, 33, 45, 57].include?(min) ? 0.001 : -0.001)).round(2)
         | 
| 33 48 | 
             
              end
         | 
| 34 49 |  | 
| 35 50 | 
             
              # xos is rounding XOJET STYLE, which is a funky copy of how ipc did it
         | 
| @@ -37,11 +52,11 @@ module TimeFunctions | |
| 37 52 | 
             
                return 0 if hour + min == 0
         | 
| 38 53 | 
             
                # It was determined that "ODD" increments of .05 (ie .15, .35, .55, .75, .95) of an hour (ie. 9,21,33,45,57 minutes) rounded UP whereas even increments of .05 rounded DOWN - sn
         | 
| 39 54 | 
             
                minutes = as_minutes
         | 
| 40 | 
            -
                (minutes/60.0 + ([9, 21, 33, 45, 57].include?( | 
| 55 | 
            +
                (minutes/60.0 + ([9, 21, 33, 45, 57].include?(min) ? 0.01 : -0.01)).round(1)
         | 
| 41 56 | 
             
              end
         | 
| 42 57 |  | 
| 43 58 | 
             
              def hm
         | 
| 44 | 
            -
                 | 
| 59 | 
            +
                strftime("%H:%M")
         | 
| 45 60 | 
             
              end
         | 
| 46 61 |  | 
| 47 62 | 
             
              def to_fos_days
         | 
| @@ -52,12 +67,10 @@ end | |
| 52 67 | 
             
            class Time
         | 
| 53 68 | 
             
              include TimeFunctions
         | 
| 54 69 |  | 
| 55 | 
            -
              DATE_FORMATS[:hm] = "%H:%M"
         | 
| 56 | 
            -
             | 
| 57 70 | 
             
              alias :original_to_s :to_s
         | 
| 58 71 |  | 
| 59 72 | 
             
              def to_s(args=nil)
         | 
| 60 | 
            -
                args  | 
| 73 | 
            +
                return self.strftime('%H:%M') if args == :hm or !args
         | 
| 61 74 | 
             
                self.original_to_s(args)
         | 
| 62 75 | 
             
              end
         | 
| 63 76 |  | 
| @@ -68,7 +81,25 @@ class Time | |
| 68 81 | 
             
              end
         | 
| 69 82 |  | 
| 70 83 | 
             
              class << self
         | 
| 71 | 
            -
                alias from_minutes from_fos_time | 
| 84 | 
            +
                alias from_minutes from_fos_time
         | 
| 85 | 
            +
              end
         | 
| 86 | 
            +
             | 
| 87 | 
            +
              ######## from Ruby Cookbook #########
         | 
| 88 | 
            +
              def to_datetime
         | 
| 89 | 
            +
                # Convert seconds + microseconds into a fractional number of seconds
         | 
| 90 | 
            +
                seconds = sec + Rational(usec, 10**6)
         | 
| 91 | 
            +
             | 
| 92 | 
            +
                # Convert a UTC offset measured in minutes to one measured in a
         | 
| 93 | 
            +
                # fraction of a day.
         | 
| 94 | 
            +
                offset = Rational(utc_offset, 60 * 60 * 24)
         | 
| 95 | 
            +
                DateTime.new(year, month, day, hour, min, seconds, offset)
         | 
| 96 | 
            +
              end
         | 
| 97 | 
            +
             | 
| 98 | 
            +
              # This is a view "February 01, 2010 01:40" that be parsed directly by javascript
         | 
| 99 | 
            +
              # ie. in javascript you can say:  Date.parse( "this to long view" )   and you
         | 
| 100 | 
            +
              # will get a date object
         | 
| 101 | 
            +
              def long_view
         | 
| 102 | 
            +
                self.strftime('%B %d, %Y %H:%M')
         | 
| 72 103 | 
             
              end
         | 
| 73 104 | 
             
            end
         | 
| 74 105 |  | 
| @@ -79,16 +110,17 @@ class DateTime | |
| 79 110 | 
             
              def self.from_fos_date_time(days, minutes)
         | 
| 80 111 | 
             
                days = 0 unless days
         | 
| 81 112 | 
             
                minutes = 0 unless minutes
         | 
| 82 | 
            -
                Date.from_fos_days(days). | 
| 113 | 
            +
                (Date.from_fos_days(days).to_gm_time + minutes.minutes).to_datetime
         | 
| 83 114 | 
             
              end
         | 
| 84 115 |  | 
| 85 116 | 
             
              def view
         | 
| 86 117 | 
             
                to_s
         | 
| 87 118 | 
             
              end
         | 
| 88 119 |  | 
| 89 | 
            -
              # This is a view that be parsed directly by javascript | 
| 90 | 
            -
              # you can say:  Date.parse( "this to long view" )   and you | 
| 120 | 
            +
              # This is a view "February 01, 2010 01:40" that be parsed directly by javascript
         | 
| 121 | 
            +
              # ie. in javascript you can say:  Date.parse( "this to long view" )   and you
         | 
| 122 | 
            +
              # will get a date object
         | 
| 91 123 | 
             
              def long_view
         | 
| 92 | 
            -
                 | 
| 124 | 
            +
                self.strftime('%B %d, %Y %H:%M')
         | 
| 93 125 | 
             
              end
         | 
| 94 126 | 
             
            end
         |