JRuby

strftime doesn't support %h

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: JRuby 1.3.1
  • Fix Version/s: JRuby 1.4
  • Component/s: Core Classes/Modules
  • Labels:
    None
  • Number of attachments :
    1

Description

JRuby just outputs %h, not the month name.

$ ruby -e 'puts Time.now.strftime("%d %h %Y")'
10 Aug 2009

$ /opt/jruby/bin/jruby -e 'puts Time.now.strftime("%d %h %Y")'
10 %h 2009

$ ruby -v
ruby 1.8.6 (2008-08-11 patchlevel 287) [i386-solaris2.10]

$ /opt/jruby/bin/jruby -v
jruby 1.3.1 (ruby 1.8.6p287) (2009-06-15 2fd6c3d) (Java HotSpot(TM) Client VM 1.6.0_11) [x86-java]

Issue Links

Activity

Hide
Ben Summers added a comment -

To be fair, %h isn't documented in the Ruby docs. However, MRI appears to use the underlying C strftime, which does tend to support more than Ruby documents.

Show
Ben Summers added a comment - To be fair, %h isn't documented in the Ruby docs. However, MRI appears to use the underlying C strftime, which does tend to support more than Ruby documents.
Hide
Hiro Asari added a comment -

For the sake of completeness, here is the diff of the documented format tokens for Time.strftime on 1.8.6/1.8.7 and 1.9.2:

@@ -3,17 +3,39 @@
 %b - The abbreviated month name (``Jan'')
 %B - The  full  month  name (``January'')
 %c - The preferred local date and time representation
+%C - Century (20 in 2009)
 %d - Day of the month (01..31)
+%D - Date (%m/%d/%y)
+%e - Day of the month, blank-padded ( 1..31)
+%F - Equivalent to %Y-%m-%d (the ISO 8601 date format)
+%h - Equivalent to %b
 %H - Hour of the day, 24-hour clock (00..23)
 %I - Hour of the day, 12-hour clock (01..12)
 %j - Day of the year (001..366)
+%k - hour, 24-hour clock, blank-padded ( 0..23)
+%l - hour, 12-hour clock, blank-padded ( 0..12)
+%L - Millisecond of the second (000..999)
 %m - Month of the year (01..12)
 %M - Minute of the hour (00..59)
+%n - Newline (\n)
+%N - Fractional seconds digits, default is 9 digits (nanosecond)
+        %3N  millisecond (3 digits)
+        %6N  microsecond (6 digits)
+        %9N  nanosecond (9 digits)
 %p - Meridian indicator (``AM''  or  ``PM'')
+%P - Meridian indicator (``am''  or  ``pm'')
+%r - time, 12-hour (same as %I:%M:%S %p)
+%R - time, 24-hour (%H:%M)
+%s - Number of seconds since 1970-01-01 00:00:00 UTC.
 %S - Second of the minute (00..60)
+%t - Tab character (\t)
+%T - time, 24-hour (%H:%M:%S)
+%u - Day of the week as a decimal, Monday being 1. (1..7)
 %U - Week  number  of the current year,
         starting with the first Sunday as the first
         day of the first week (00..53)
+%v - VMS date (%e-%b-%Y)
+%V - Week number of year according to ISO 8601 (01..53)
 %W - Week  number  of the current year,
         starting with the first Monday as the first
         day of the first week (00..53)
@@ -22,5 +44,6 @@
 %X - Preferred representation for the time alone, no date
 %y - Year without a century (00..99)
 %Y - Year with century
+%z - Time zone as  hour offset from UTC (e.g. +0900)
 %Z - Time zone name
 %% - Literal ``%'' character

The attached patch implements most of these, except "%10N".

Dealing with this sort of token turns out to be problematic. For example, in Ruby 1.9.2dev, if you specify "%5Z", the string is padded with white spaces to be 5 characters long, e.g., "  CDT".

Show
Hiro Asari added a comment - For the sake of completeness, here is the diff of the documented format tokens for Time.strftime on 1.8.6/1.8.7 and 1.9.2:
@@ -3,17 +3,39 @@
 %b - The abbreviated month name (``Jan'')
 %B - The  full  month  name (``January'')
 %c - The preferred local date and time representation
+%C - Century (20 in 2009)
 %d - Day of the month (01..31)
+%D - Date (%m/%d/%y)
+%e - Day of the month, blank-padded ( 1..31)
+%F - Equivalent to %Y-%m-%d (the ISO 8601 date format)
+%h - Equivalent to %b
 %H - Hour of the day, 24-hour clock (00..23)
 %I - Hour of the day, 12-hour clock (01..12)
 %j - Day of the year (001..366)
+%k - hour, 24-hour clock, blank-padded ( 0..23)
+%l - hour, 12-hour clock, blank-padded ( 0..12)
+%L - Millisecond of the second (000..999)
 %m - Month of the year (01..12)
 %M - Minute of the hour (00..59)
+%n - Newline (\n)
+%N - Fractional seconds digits, default is 9 digits (nanosecond)
+        %3N  millisecond (3 digits)
+        %6N  microsecond (6 digits)
+        %9N  nanosecond (9 digits)
 %p - Meridian indicator (``AM''  or  ``PM'')
+%P - Meridian indicator (``am''  or  ``pm'')
+%r - time, 12-hour (same as %I:%M:%S %p)
+%R - time, 24-hour (%H:%M)
+%s - Number of seconds since 1970-01-01 00:00:00 UTC.
 %S - Second of the minute (00..60)
+%t - Tab character (\t)
+%T - time, 24-hour (%H:%M:%S)
+%u - Day of the week as a decimal, Monday being 1. (1..7)
 %U - Week  number  of the current year,
         starting with the first Sunday as the first
         day of the first week (00..53)
+%v - VMS date (%e-%b-%Y)
+%V - Week number of year according to ISO 8601 (01..53)
 %W - Week  number  of the current year,
         starting with the first Monday as the first
         day of the first week (00..53)
@@ -22,5 +44,6 @@
 %X - Preferred representation for the time alone, no date
 %y - Year without a century (00..99)
 %Y - Year with century
+%z - Time zone as  hour offset from UTC (e.g. +0900)
 %Z - Time zone name
 %% - Literal ``%'' character
The attached patch implements most of these, except "%10N". Dealing with this sort of token turns out to be problematic. For example, in Ruby 1.9.2dev, if you specify "%5Z", the string is padded with white spaces to be 5 characters long, e.g., "  CDT".
Hide
Hiro Asari added a comment -

FYI: In 1.9, Time.strftime intentionally mimics certain behaviors of GNU C library's strftime().

Consider the following:

surfboard:~$ ruby19 -v -S irb
ruby 1.9.2dev (2009-07-31 trunk 24332) [i386-darwin9.7.0]
irb(main):001:0> Time.now.strftime("%h")
=> "Aug"
irb(main):002:0> Time.now.strftime("%10h")
=> "       Aug"
irb(main):003:0> Time.now.strftime("%010h")
=> "0000000Aug"
irb(main):004:0> Time.now.strftime("%^010h")
=> "0000000AUG"
irb(main):005:0> Time.now.strftime("%^-10h")
=> "AUG"
irb(main):006:0> Time.now.strftime("%^h")
=> "AUG"
Show
Hiro Asari added a comment - FYI: In 1.9, Time.strftime intentionally mimics certain behaviors of GNU C library's strftime(). Consider the following:
surfboard:~$ ruby19 -v -S irb
ruby 1.9.2dev (2009-07-31 trunk 24332) [i386-darwin9.7.0]
irb(main):001:0> Time.now.strftime("%h")
=> "Aug"
irb(main):002:0> Time.now.strftime("%10h")
=> "       Aug"
irb(main):003:0> Time.now.strftime("%010h")
=> "0000000Aug"
irb(main):004:0> Time.now.strftime("%^010h")
=> "0000000AUG"
irb(main):005:0> Time.now.strftime("%^-10h")
=> "AUG"
irb(main):006:0> Time.now.strftime("%^h")
=> "AUG"
Hide
Charles Oliver Nutter added a comment -

I pushed your patch in a74827e, since even without the remaining cases it solves the original issue. You can file separate bugs for the remaining cases that are unsupported or incomplete.

We also have no tests or specs for this, and there should definitely be specs. I'll post this bug to the rubyspec ML and see if someone can pick it up, because I'm not going to right now.

Show
Charles Oliver Nutter added a comment - I pushed your patch in a74827e, since even without the remaining cases it solves the original issue. You can file separate bugs for the remaining cases that are unsupported or incomplete. We also have no tests or specs for this, and there should definitely be specs. I'll post this bug to the rubyspec ML and see if someone can pick it up, because I'm not going to right now.

People

Vote (0)
Watch (1)

Dates

  • Created:
    Updated:
    Resolved: