<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -45,7 +45,8 @@ module Chronic
       default_options = {:context =&gt; :future,
                          :now =&gt; Time.now,
                          :guess =&gt; true,
-                         :ambiguous_time_range =&gt; 6}
+                         :ambiguous_time_range =&gt; 6,
+                         :endian_precedence =&gt; nil}
       options = default_options.merge specified_options
       
       # handle options that were set to nil
@@ -244,4 +245,4 @@ module Chronic
   class InvalidArgumentException &lt; Exception
     
   end
-end
\ No newline at end of file
+end</diff>
      <filename>lib/chronic/chronic.rb</filename>
    </modified>
    <modified>
      <diff>@@ -2,7 +2,23 @@ module Chronic
 
 	class &lt;&lt; self
 	  
-	  def definitions #:nodoc:
+    def definitions(options={}) #:nodoc:
+      options[:endian_precedence] = [:middle, :little] if options[:endian_precedence].nil?
+      
+      # ensure the endian precedence is exactly two elements long
+      raise ChronicPain, &quot;More than two elements specified for endian precedence array&quot; unless options[:endian_precedence].length == 2
+
+      # handler for dd/mm/yyyy
+      @little_endian_handler ||= Handler.new([:scalar_day, :separator_slash_or_dash, :scalar_month, :separator_slash_or_dash, :scalar_year, :separator_at?, 'time?'], :handle_sd_sm_sy)
+
+      # handler for mm/dd/yyyy
+      @middle_endian_handler ||= Handler.new([:scalar_month, :separator_slash_or_dash, :scalar_day, :separator_slash_or_dash, :scalar_year, :separator_at?, 'time?'], :handle_sm_sd_sy)
+
+      # ensure we have valid endian values
+      options[:endian_precedence].each do |e|
+        raise ChronicPain, &quot;Unknown endian type: #{e.to_s}&quot; unless instance_variable_defined?(endian_variable_name_for(e))
+      end
+
 	    @definitions ||= 
       {:time =&gt; [Handler.new([:repeater_time, :repeater_day_portion?], nil)],
         
@@ -15,8 +31,8 @@ module Chronic
                  Handler.new([:repeater_time, :repeater_day_portion?, :separator_on?, :repeater_month_name, :ordinal_day], :handle_rmn_od_on),
                  Handler.new([:repeater_month_name, :scalar_year], :handle_rmn_sy),
                  Handler.new([:scalar_day, :repeater_month_name, :scalar_year, :separator_at?, 'time?'], :handle_sd_rmn_sy),
-                 Handler.new([:scalar_month, :separator_slash_or_dash, :scalar_day, :separator_slash_or_dash, :scalar_year, :separator_at?, 'time?'], :handle_sm_sd_sy),
-                 Handler.new([:scalar_day, :separator_slash_or_dash, :scalar_month, :separator_slash_or_dash, :scalar_year, :separator_at?, 'time?'], :handle_sd_sm_sy),
+                 @middle_endian_handler,
+                 @little_endian_handler,
                  Handler.new([:scalar_year, :separator_slash_or_dash, :scalar_month, :separator_slash_or_dash, :scalar_day, :separator_at?, 'time?'], :handle_sy_sm_sd),
                  Handler.new([:scalar_month, :separator_slash_or_dash, :scalar_year], :handle_sm_sy)],
                  
@@ -34,13 +50,18 @@ module Chronic
        :narrow =&gt; [Handler.new([:ordinal, :repeater, :separator_in, :repeater], :handle_o_r_s_r),
                    Handler.new([:ordinal, :repeater, :grabber, :repeater], :handle_o_r_g_r)]
       }
+      
+      apply_endian_precedences(options[:endian_precedence])
+      
+      @definitions
     end
     
     def tokens_to_span(tokens, options) #:nodoc:
       # maybe it's a specific date
       
-      self.definitions[:date].each do |handler|
-        if handler.match(tokens, self.definitions)
+      definitions = self.definitions(options)
+      definitions[:date].each do |handler|
+        if handler.match(tokens, definitions)
           puts &quot;-date&quot; if Chronic.debug
           good_tokens = tokens.select { |o| !o.get_tag Separator }
           return self.send(handler.handler_method, good_tokens, options)
@@ -49,8 +70,8 @@ module Chronic
             
       # I guess it's not a specific date, maybe it's just an anchor
             
-      self.definitions[:anchor].each do |handler|
-        if handler.match(tokens, self.definitions)
+      definitions[:anchor].each do |handler|
+        if handler.match(tokens, definitions)
           puts &quot;-anchor&quot; if Chronic.debug
           good_tokens = tokens.select { |o| !o.get_tag Separator }
           return self.send(handler.handler_method, good_tokens, options)
@@ -59,8 +80,8 @@ module Chronic
             
       # not an anchor, perhaps it's an arrow
       
-      self.definitions[:arrow].each do |handler|
-        if handler.match(tokens, self.definitions)
+      definitions[:arrow].each do |handler|
+        if handler.match(tokens, definitions)
           puts &quot;-arrow&quot; if Chronic.debug
           good_tokens = tokens.reject { |o| o.get_tag(SeparatorAt) || o.get_tag(SeparatorSlashOrDash) || o.get_tag(SeparatorComma) }
           return self.send(handler.handler_method, good_tokens, options)
@@ -69,8 +90,8 @@ module Chronic
       
       # not an arrow, let's hope it's a narrow
       
-      self.definitions[:narrow].each do |handler|
-        if handler.match(tokens, self.definitions)
+      definitions[:narrow].each do |handler|
+        if handler.match(tokens, definitions)
           puts &quot;-narrow&quot; if Chronic.debug
           #good_tokens = tokens.select { |o| !o.get_tag Separator }
           return self.send(handler.handler_method, tokens, options)
@@ -84,6 +105,26 @@ module Chronic
     
     #--------------
     
+    def apply_endian_precedences(precedences)
+      date_defs = @definitions[:date]
+
+      # map the precedence array to indices on @definitions[:date]
+      indices = precedences.map { |e|
+        handler = instance_variable_get(endian_variable_name_for(e))
+        date_defs.index(handler)
+      }
+
+      # swap the handlers if we discover they are at odds with the desired preferences
+      swap(date_defs, indices.first, indices.last) if indices.first &gt; indices.last
+    end
+
+    def endian_variable_name_for(e)
+      &quot;@#{e.to_s}_endian_handler&quot;.to_sym
+    end
+
+    # exchange two elements in an array
+    def swap(arr, a, b); arr[a], arr[b] = arr[b], arr[a]; end
+
     def day_or_time(day_start, time_tokens, options)
       outer_span = Span.new(day_start, day_start + (24 * 60 * 60))
       
@@ -474,6 +515,10 @@ module Chronic
       return false if token_index != tokens.size
       return true
     end
+
+    def ==(other)
+      self.pattern == other.pattern
+    end
   end
   
-end
\ No newline at end of file
+end</diff>
      <filename>lib/chronic/handlers.rb</filename>
    </modified>
    <modified>
      <diff>@@ -611,6 +611,20 @@ class TestParsing &lt; Test::Unit::TestCase
     assert_equal Time.local(2006, 8, 21), span.end
   end
   
+  def test_parse_with_endian_precedence
+    date = '11/02/2007'
+
+    expect_for_middle_endian = Time.local(2007, 11, 2, 12)
+    expect_for_little_endian = Time.local(2007, 2, 11, 12)
+
+    # default precedence should be toward middle endianness
+    assert_equal expect_for_middle_endian, Chronic.parse(date)
+
+    assert_equal expect_for_middle_endian, Chronic.parse(date, :endian_precedence =&gt; [:middle, :little])
+
+    assert_equal expect_for_little_endian, Chronic.parse(date, :endian_precedence =&gt; [:little, :middle])
+  end
+
   def test_parse_words
     assert_equal parse_now(&quot;33 days from now&quot;), parse_now(&quot;thirty-three days from now&quot;)
     assert_equal parse_now(&quot;2867532 seconds from now&quot;), parse_now(&quot;two million eight hundred and sixty seven thousand five hundred and thirty two seconds from now&quot;)
@@ -689,4 +703,4 @@ class TestParsing &lt; Test::Unit::TestCase
   def parse_now(string, options={})
     Chronic.parse(string, {:now =&gt; TIME_2006_08_16_14_00_00 }.merge(options))
   end
-end
\ No newline at end of file
+end</diff>
      <filename>test/test_parsing.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>66a0d3faf30584b4b10a3bd72b21246e8a299d8a</id>
    </parent>
  </parents>
  <author>
    <name>Tom Preston-Werner</name>
    <email>tom@mojombo.com</email>
  </author>
  <url>http://github.com/technoweenie/chronic/commit/bd654b26ab052a74aab15c8e1a6e026a8010458b</url>
  <id>bd654b26ab052a74aab15c8e1a6e026a8010458b</id>
  <committed-date>2008-02-19T23:56:48-08:00</committed-date>
  <authored-date>2008-02-19T23:56:48-08:00</authored-date>
  <message>add endianness option (Mark Johnson/Thomas Lee)</message>
  <tree>8e222e5102accd8b27c826f976f7b01d79085479</tree>
  <committer>
    <name>Tom Preston-Werner</name>
    <email>tom@mojombo.com</email>
  </committer>
</commit>
