Professional Web Applications Themes

date/format.rb fix - Ruby

Hello, The _p() function of date/format.rb does not handle fractions of seconds. Eg, the string 2004-02-12 12:23:45.581297-07 causes the pr to miss the timezone offset. Postgresql returns timestamp columns like this, thus breaking ruby-dbi. A simple change to the regex can fix this: --- date/format.rb.orig 2004-02-24 12:07:42.000000000 -0800 +++ date/format.rb 2004-02-24 12:03:12.000000000 -0800 -236,7 +236,7 class Date # time if str.sub!( - /(\d+):(\d+)(?::(\d+))? + /(\d+):(\d+)(?::(\d+)(?:\.\d+)?)? (?: \s* ([ap])(?:m\b|\.m\.) Would someone please consider applying this fix? Thanks, Brad Hilton VPOP Technologies, Inc. net...

  1. #1

    Default date/format.rb fix

    Hello,

    The _p() function of date/format.rb does not handle fractions of
    seconds. Eg, the string

    2004-02-12 12:23:45.581297-07

    causes the pr to miss the timezone offset. Postgresql returns
    timestamp columns like this, thus breaking ruby-dbi.

    A simple change to the regex can fix this:

    --- date/format.rb.orig 2004-02-24 12:07:42.000000000 -0800
    +++ date/format.rb 2004-02-24 12:03:12.000000000 -0800
    -236,7 +236,7 class Date

    # time
    if str.sub!(
    - /(\d+):(\d+)(?::(\d+))?
    + /(\d+):(\d+)(?::(\d+)(?:\.\d+)?)?
    (?:
    \s*
    ([ap])(?:m\b|\.m\.)

    Would someone please consider applying this fix?

    Thanks,

    Brad Hilton
    VPOP Technologies, Inc.
    net



    Brad Guest

  2. #2

    Default Re: date/format.rb fix

    Hi,
     
     

    You got that right.
     
     

    Drop fractions?

    /(\d+):(\d+)(?::(\d+(?:\.\d+)?))?

    Could be better but I don't know how we treat $3 string.
    $3 is converted to Integer via to_i now. Float? Rational?

    The author Funaba-san merely seen in this ML. I'll forward it
    some later date.

    Regards,
    // NaHi


    NAKAMURA, Guest

  3. #3

    Default Re: date/format.rb fix

    NAKAMURA, Hiroshi wrote: 

    >

    >
    >
    > Drop fractions?
    >
    > /(\d+):(\d+)(?::(\d+(?:\.\d+)?))?
    >
    > Could be better but I don't know how we treat $3 string.
    > $3 is converted to Integer via to_i now. Float? Rational?[/ref]

    I wasn't sure - that's why I updated the regex to simply drop the
    fraction. :) Dropping the fraction is not ideal, but at least people
    won't have any unpleasant surprises if they are expecting the current
    behavior (converting the seconds to an int).
     

    Thank you.

    -Brad


    Brad Guest

Similar Threads

  1. Different date format
    By Jihaes in forum Macromedia Flex General Discussion
    Replies: 2
    Last Post: July 24th, 06:51 PM
  2. Date format
    By Mercury in forum Ubuntu
    Replies: 4
    Last Post: July 12th, 08:03 PM
  3. PHP date format
    By erickia in forum Dreamweaver AppDev
    Replies: 2
    Last Post: May 17th, 07:05 PM
  4. Date Format pb
    By Franck in forum ASP.NET Web Services
    Replies: 1
    Last Post: April 21st, 05:55 PM
  5. converting date into database date format(newbie)
    By Binay Agarwal in forum PHP Development
    Replies: 2
    Last Post: August 29th, 01:09 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139