I've tried to do the best research I can into this before posting here,
but I have come up relatively short. I would like to format a DateTime
such that the day of the month and hours that are less than ten are not
prefixed with a leading zero (ex. Jan 4 9:30 and not Jan 04 09:30).
Is there any way to use DateTime#strftime to do this, or any
alternative short of piecing the bits together with calls like
thedate.month + " " + thedate.day?
Thank you.
Sincerely,
Tom Reinhart
tom@alltom.com
http://alltom.com/
Tom,
The best I could come up with is ...
heron $ irb
irb(main):001:0> t=Time.local(2005,'jan',4,9,05,0,0)
=> Tue Jan 04 09:05:00 PST 2005
irb(main):002:0> t.strftime('%b %d %Y %H:%M').gsub(/ 0(\d\D)/, ' \1')
=> "Jan 4 2005 9:05"
irb(main):003:0>
Hope this helps.
Vance
···
On Sun, 2005-05-15 at 17:10 +0900, Tom Reinhart wrote:
I've tried to do the best research I can into this before posting here,
but I have come up relatively short. I would like to format a DateTime
such that the day of the month and hours that are less than ten are not
prefixed with a leading zero (ex. Jan 4 9:30 and not Jan 04 09:30).
Is there any way to use DateTime#strftime to do this, or any
alternative short of piecing the bits together with calls like
thedate.month + " " + thedate.day?
Thank you.
Sincerely,
Tom Reinhart
tom@alltom.com
http://alltom.com/
Hi,
At Sun, 15 May 2005 17:53:05 +0900,
Vance A Heron wrote in [ruby-talk:142690]:
irb(main):001:0> t=Time.local(2005,'jan',4,9,05,0,0)
=> Tue Jan 04 09:05:00 PST 2005
irb(main):002:0> t.strftime('%b %d %Y %H:%M').gsub(/ 0(\d\D)/, ' \1')
=> "Jan 4 2005 9:05"
irb(main):003:0> t.strftime('%b %-2d %Y %-2H:%-2M')
=> "Jan 4 2005 9: 5"
···
--
Nobu Nakada
irb(main):001:0> t=Time.local(2005,'jan',4,9,05,0,0)
=> Tue Jan 04 09:05:00 PST 2005
irb(main):002:0> t.strftime('%b %d %Y %H:%M').gsub(/ 0(\d\D)/, ' \1')
=> "Jan 4 2005 9:05"
irb(main):003:0>
Hope this helps.
Vance
Okay, so it looks like I can use a regular expression for removing the
leading zero ...
I think the %e and %l modifiers will give you the day of month and
the
hour without 0's, but with spaces (i.e., space-padded). Looking at
date/format.rb I don't see a way to suppress the padding.
David
.... or I can use a regular expression for removing the repeated spaces.
(Thanks for the hints about using Time.strftime, but if it's really
system dependent, I think I'll go the regex route.) Thanks, all, very
much. 
Sincerely,
Tom Reinhart
tom@alltom.com
http://alltom.com/
Hi,
At Sun, 15 May 2005 21:01:23 +0900,
David A. Black wrote in [ruby-talk:142696]:
> irb(main):003:0> t.strftime('%b %-2d %Y %-2H:%-2M')
> => "Jan 4 2005 9: 5"
I hadn't thought to look there -- I'd tried something like:
irb(main):002:0> Date.today.strftime('%b %-2d %Y %-2H:%-2M')
which gave me:
=> "May %-2d 2005 %-2H:%-2M"
It looks like system dependent.


···
--
Nobu Nakada
Hi,
At Sun, 15 May 2005 21:01:23 +0900,
David A. Black wrote in [ruby-talk:142696]:
> irb(main):003:0> t.strftime('%b %-2d %Y %-2H:%-2M')
> => "Jan 4 2005 9: 5"
I hadn't thought to look there -- I'd tried something like:
irb(main):002:0> Date.today.strftime('%b %-2d %Y %-2H:%-2M')
which gave me:
=> "May %-2d 2005 %-2H:%-2M"
It looks like system dependent.
I think he was saying that Date will not do it while Time
will (with Matz-ue providing an explanation for this).
It is still, of course, system-dependent for Time.


Nobu Nakada
E
···
Le 15/5/2005, "nobu.nokada@softhome.net" <nobu.nokada@softhome.net> a écrit:
--
template<typename duck>
void quack(duck& d) { d.quack(); }
Hi --
Le 15/5/2005, "nobu.nokada@softhome.net" <nobu.nokada@softhome.net> a
écrit:
Hi,
At Sun, 15 May 2005 21:01:23 +0900,
David A. Black wrote in [ruby-talk:142696]:
irb(main):003:0> t.strftime('%b %-2d %Y %-2H:%-2M')
=> "Jan 4 2005 9: 5"
I hadn't thought to look there -- I'd tried something like:
irb(main):002:0> Date.today.strftime('%b %-2d %Y %-2H:%-2M')
which gave me:
=> "May %-2d 2005 %-2H:%-2M"
It looks like system dependent.
I think he was saying that Date will not do it while Time
will (with Matz-ue providing an explanation for this).
Yes, except for the part about Matz providing an explanation. Or did
I miss that?
Actually, it was a separate thread, I did not even realize it.
Essentially, Date is parsed with code by the Ruby team while
Time is parsed with strftime from the underlying platform.
See thread "Possible bug in Date/ParseDate"
David
David A. Black
E
···
Le 15/5/2005, "David A. Black" <dblack@wobblini.net> a écrit:
On Sun, 15 May 2005, ES wrote:
--
template<typename duck>
void quack(duck& d) { d.quack(); }
See thread "Possible bug in Date/ParseDate"
i think that was the thread i started.
i write a lot of log/time manipulation code (in all the languages i work in) so i usually run into date/time bugs or inconsistencies...
···
--
http://home.cogeco.ca/~tsummerfelt1
telnet://ventedspleen.dyndns.org