I am trying to format some datetimes like this...2007, February the 9th, 6:30pm I have the following which gets me part way there. ActiveSupport::CoreExtensions::Time::Conversions::DATE_FORMATS.update(:my_date_format => "%Y, %d %B, %I:%M%p") There are 2 problems 1. There is no "th" formatter so that I get 1st, 2nd, 3rd, 4th, 5th, etc. 2. PM is in uppercase and I would prefer it in lower. TIA --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
This question may be too hard for those here :-) I understand that 1.ordinalize is ''1st'' (Edge) and ''PM''.downcase is ''pm'' but I dont see how it can be applied to Conversions for my custom formatter. Also the hours portion (%I) of the time format make 06 instead of 6, really, normal people just don''t write 06:30 On Feb 9, 6:53 pm, "reed" <reed...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I am trying to format some datetimes like this...2007, February the > 9th, 6:30pm > > I have the following which gets me part way there. > > ActiveSupport::CoreExtensions::Time::Conversions::DATE_FORMATS.update(:my_date_format > => "%Y, %d %B, %I:%M%p") > > There are 2 problems > 1. There is no "th" formatter so that I get 1st, 2nd, 3rd, 4th, 5th, > etc. > 2. PM is in uppercase and I would prefer it in lower. > > TIA--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
njmacinnes-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2007-Feb-10 12:07 UTC
Re: Problem changing datetime format
ActiveSupport::CoreExtensions::Time::Conversions::DATE_FORMATS.update(:my_date_format => "%Y, %d %B, %l:%M%P") That should do it. On 10/02/07, reed <reedrob-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > This question may be too hard for those here :-) > > I understand that 1.ordinalize is ''1st'' (Edge) and ''PM''.downcase is > ''pm'' but I dont see how it can be applied to Conversions for my custom > formatter. > > Also the hours portion (%I) of the time format make 06 instead of 6, > really, normal people just don''t write 06:30 > > On Feb 9, 6:53 pm, "reed" <reed...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > I am trying to format some datetimes like this...2007, February the > > 9th, 6:30pm > > > > I have the following which gets me part way there. > > > > > ActiveSupport::CoreExtensions::Time::Conversions::DATE_FORMATS.update(:my_date_format > > => "%Y, %d %B, %I:%M%p") > > > > There are 2 problems > > 1. There is no "th" formatter so that I get 1st, 2nd, 3rd, 4th, 5th, > > etc. > > 2. PM is in uppercase and I would prefer it in lower. > > > > TIA > > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Feb 10, 2007, at 3:19 AM, reed wrote:> This question may be too hard for those here :-) > > I understand that 1.ordinalize is ''1st'' (Edge) and ''PM''.downcase is > ''pm'' but I dont see how it can be applied to Conversions for my custom > formatter. > > Also the hours portion (%I) of the time format make 06 instead of 6, > really, normal people just don''t write 06:30 > > On Feb 9, 6:53 pm, "reed" <reed...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> I am trying to format some datetimes like this...2007, February the >> 9th, 6:30pm >> >> I have the following which gets me part way there. >> >> ActiveSupport::CoreExtensions::Time::Conversions::DATE_FORMATS.update >> (:my_date_format >> => "%Y, %d %B, %I:%M%p") >> >> There are 2 problems >> 1. There is no "th" formatter so that I get 1st, 2nd, 3rd, 4th, 5th, >> etc. >> 2. PM is in uppercase and I would prefer it in lower. >> >> TIASince the DATE_FORMATS are simple strftime() formatting specs, you can''t just create that format. However, you can roll your own (even making it part of Time if you want) like this: require ''rubygems'' gem ''activesupport'', ">=1.4" require ''active_support'' t = Time.now class Time def my_time hr = hour % 12 hr = 12 if hr.zero? "%d, %s the %s, %d:%02d%s" % [ year, strftime("%B"), day.ordinalize, hr, min, strftime("%p").downcase ] end end puts t puts t.my_time -Rob Rob Biedenharn http://agileconsultingllc.com Rob-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
njmacinnes-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2007-Feb-11 01:23 UTC
Re: Problem changing datetime format
Well... http://wiki.rubyonrails.com/rails/pages/HowToDefineYourOwnDateFormat On 10/02/07, Rob Biedenharn <Rob-GBZH0y1GwQfnZcttdmLDtcI/UQi/AW5J@public.gmane.org> wrote:> > > On Feb 10, 2007, at 3:19 AM, reed wrote: > > This question may be too hard for those here :-) > > > > I understand that 1.ordinalize is ''1st'' (Edge) and ''PM''.downcase is > > ''pm'' but I dont see how it can be applied to Conversions for my custom > > formatter. > > > > Also the hours portion (%I) of the time format make 06 instead of 6, > > really, normal people just don''t write 06:30 > > > > On Feb 9, 6:53 pm, "reed" <reed...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > >> I am trying to format some datetimes like this...2007, February the > >> 9th, 6:30pm > >> > >> I have the following which gets me part way there. > >> > >> ActiveSupport::CoreExtensions::Time::Conversions::DATE_FORMATS.update > >> (:my_date_format > >> => "%Y, %d %B, %I:%M%p") > >> > >> There are 2 problems > >> 1. There is no "th" formatter so that I get 1st, 2nd, 3rd, 4th, 5th, > >> etc. > >> 2. PM is in uppercase and I would prefer it in lower. > >> > >> TIA > > Since the DATE_FORMATS are simple strftime() formatting specs, you > can''t just create that format. However, you can roll your own (even > making it part of Time if you want) like this: > > require ''rubygems'' > gem ''activesupport'', ">=1.4" > require ''active_support'' > > t = Time.now > > class Time > def my_time > hr = hour % 12 > hr = 12 if hr.zero? > "%d, %s the %s, %d:%02d%s" % [ year, strftime("%B"), > day.ordinalize, > hr, min, strftime("%p").downcase ] > end > end > > puts t > puts t.my_time > > -Rob > > Rob Biedenharn http://agileconsultingllc.com > Rob-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org > > > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---