Subject: Re: [sup-devel] [PATCH] fixed am/pm in thread-list-mode for ruby1.8

From: Benoît PIERRE <[email-masked]>
Date: Thu, 31 Dec 2009 22:27:41 +0100

Excerpts from Eric Sherman's message of Thu Dec 31 22:03:40 +0100 2009:
> Excerpts from William Morgan's message of Thu Dec 31 15:14:50 -0500 2009:
> > Reformatted excerpts from Eric Sherman's message of 2009-12-31:
> > > %P in 1.8.7 displays a literal "P" always, whereas %P in 1.9 display am/pm.
> > 
> > That's not the case for me. I get an am/pm for 1.8.7 patch levels 174
> > and 72 (the two I have on hand). Unless there's some weird Debian
> > patching going on.
> > 
> > Can anyone else confirm?
> 
> Here's a simple test for others to try:
> 
>     $ ruby --version
>     ruby 1.8.7 (2009-06-12 patchlevel 174) [i686-darwin10]
>     $ irb
>     irb(main):001:0> RUBY_VERSION
>     => "1.8.7"
>     irb(main):002:0> Time.now().strftime("%l:%M%P")
>     => " 3:58P"
>     irb(main):003:0> quit
>     $ ruby1.9 --version
>     ruby 1.9.1p376 (2009-12-07 revision 26041) [i386-darwin10]
>     $ irb1.9 irb(main):001:0> RUBY_VERSION
>     => "1.9.1"
>     irb(main):002:0> Time.now().strftime("%l:%M%P")
>     => " 3:58pm"

# ruby --version
ruby 1.8.7 (2009-06-12 patchlevel 174) [x86_64-linux]
# ruby -e 'puts Time.now().strftime("%l:%M%P")'
10:21pm

# ruby1.9 --version
ruby 1.9.0 (2008-10-04 revision 19669) [x86_64-linux]
# ruby1.9 -e 'puts Time.now().strftime("%l:%M%P")'
10:22pm

That's on Ubuntu Karmic.
-- 
A: Because it destroys the flow of conversation.
Q: Why is top posting dumb?
_______________________________________________
Sup-devel mailing list
[email-masked]
http://rubyforge.org/mailman/listinfo/sup-devel

---

From: Eric Sherman <[email-masked]>
Date: Thu, 31 Dec 2009 09:48:25 -0500

Here's a patch that gives the proper am/pm display for ruby1.8 if that's 
what's running.

---
 lib/sup/util.rb |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/lib/sup/util.rb b/lib/sup/util.rb
index f99e1c1..1a2a447 100644
--- a/lib/sup/util.rb
+++ b/lib/sup/util.rb
@@ -486,9 +486,9 @@ class Time
       strftime "%b %e"
     else
       if is_the_same_day? from
-        strftime("%l:%M%P")
+        (RUBY_VERSION =~ /^1.8/) ? strftime("%l:%M%p").downcase : strftime("%l:%M%P")
       elsif is_the_day_before? from
-        "Yest."  + nearest_hour.strftime("%l%P")
+        "Yest." + ((RUBY_VERSION =~ /^1.8/) ? nearest_hour.strftime("%l%p").downcase : nearest_hour.strftime("%l%P"))
       else
         strftime "%b %e"
       end
-- 
1.6.5.7
_______________________________________________
Sup-devel mailing list
[email-masked]
http://rubyforge.org/mailman/listinfo/sup-devel

---

From: Eric Sherman <[email-masked]>
Date: Thu, 31 Dec 2009 17:10:45 -0500

> # ruby1.9 -e 'puts Time.now().strftime("%l:%M%P")'

Hmm.  Maybe this issue only exists on OSX.  I'm kind of jealous that linux 
rubies get features from the future!  I first heard about this AM/PM 
behavior from [this][1] sup-talk thread and hadn't noticed it myself until 
then.

[1]: http://rubyforge.org/pipermail/sup-talk/2009-December/003599.html
_______________________________________________
Sup-devel mailing list
[email-masked]
http://rubyforge.org/mailman/listinfo/sup-devel

---

From: Eric Sherman <[email-masked]>
Date: Thu, 31 Dec 2009 16:03:40 -0500

$ ruby --version

---

From: Blake Burkhart <[email-masked]>
Date: Fri, 01 Jan 2010 23:59:08 -0600

Excerpts from William Morgan's message of Fri Jan 01 09:13:08 -0600 2010:
> > Hmm.  Maybe this issue only exists on OSX.
> 
> I suspect so. Can you provide a patch that uses the downcase trick and
> doesn't check for the ruby version or the OS? (Maybe with a helpful
> comment.) That should work everywhere, lame as it may be.

I don't know if you need any more examples of this, but I'm running Mac OS
10.6, and can reproduce this with the three different versions of ruby I
happen to have installed.

Apple supplied ruby:
$ /usr/bin/ruby --version
ruby 1.8.7 (2008-08-11 patchlevel 72) [universal-darwin10.0]
$ /usr/bin/ruby -e 'puts Time.now().strftime("%l:%M%P")'
11:27P

Ruby from the MacPorts package manager, patchlevel 174:
$ ruby --version
ruby 1.8.7 (2009-06-12 patchlevel 174) [i686-darwin10]
$ ruby -e 'puts Time.now().strftime("%l:%M%P")'
11:25P

And [MacRuby][1], which is completely beta everything, but is 1.9:
$ macruby --version
MacRuby version 0.5 (ruby 1.9.0) [universal-darwin10.0, x86_64]
$ macruby -e 'puts Time.now().strftime("%l:%M%P")'
11:25P

I'm pretty sure that *should* work on MacRuby, but it's not. I think that's
possibly their fault though. I guess I could report it as a bug to them then.
I'm not really using that ruby version for anything, so I don't know how
complete it is.

[1]: http://www.macruby.org/

-- 
Blake Burkhart

---

From: William Morgan <[email-masked]>
Date: Fri, 01 Jan 2010 07:13:08 -0800

William <[email-masked]>

---

From: Eric Sherman <[email-masked]>
Date: Sat, 02 Jan 2010 01:13:50 -0500

> [1]: http://www.macruby.org/

I've resubmitted the patch in a new thread titled "[PATCH] fixed am/pm 
display for ruby 1.8 darwin (v2)", but like William says it should work 
everywhere including MacRuby because it just emulate's %P by downcase()ing 
%p.
_______________________________________________
Sup-devel mailing list
[email-masked]
http://rubyforge.org/mailman/listinfo/sup-devel

---

From: William Morgan <[email-masked]>
Date: Thu, 31 Dec 2009 12:14:50 -0800

Can anyone else confirm?

---

From: Eric Sherman <[email-masked]>
Date: Thu, 31 Dec 2009 15:03:18 -0500

Excerpts from William Morgan's message of Thu Dec 31 14:53:53 -0500 2009:
> > Here's a patch that gives the proper am/pm display for ruby1.8 if
> > that's what's running.
> 
> Can you give a little more info? My ruby 1.8.7 is fine with %P. Was this
> broken in earlier 1.8's?

%p in both 1.8.7 and 1.9 displays AM/PM.

ruby1.8.7 strftime: http://ruby-doc.org/core-1.8.7/classes/Time.html#M000139
ruby1.9 strftime: http://ruby-doc.org/core-1.9/classes/Time.html#M000314

I didn't notice it until someone else mentioned it.
_______________________________________________
Sup-devel mailing list
[email-masked]
http://rubyforge.org/mailman/listinfo/sup-devel

---

From: William Morgan <[email-masked]>
Date: Thu, 31 Dec 2009 11:53:53 -0800