H
Harold Hausman
I've got strings created by doing something on the order of
DateTime.now.to_s stored away.
When I'm reading them out, and showing them to the user I want to see
something pretty like:
Sat Mar 10 at 12:34pm
Heres the code I came up with:
def timeFormat( in_str )
=09the_date =3D DateTime.parse( in_str )
=09the_date =3D the_date.new_offset( -7.0/24.0 )
=09nice_date =3D ''
=09nice_date +=3D case the_date.cwday
=09=09when 1; "Mon "
=09=09when 2; "Tue "
=09=09when 3; "Wed "
=09=09when 4; "Thu "
=09=09when 5; "Fri "
=09=09when 6; "Sat "
=09=09when 7; "Sun "
=09end
=09nice_date +=3D case the_date.month
=09=09when 1; "Jan "
=09=09when 2; "Feb "
=09=09when 3; "Mar "
=09=09when 4; "Apr "
=09=09when 5; "May "
=09=09when 6; "Jun "
=09=09when 7; "Jul "
=09=09when 8; "Aug "
=09=09when 9; "Sep "
=09=09when 10; "Oct "
=09=09when 11; "Nov "
=09=09when 12; "Dec "
=09end
=09nice_date +=3D the_date.day.to_s + ' at '
=09the_minute =3D the_date.min
=09if( the_minute < 10 )
=09=09the_minute =3D "0"+the_minute.to_s
=09else
=09=09the_minute =3D the_minute.to_s
=09end
=09if( the_date.hour < 12 )
=09=09nice_date +=3D the_date.hour.to_s + ":" + the_minute + "am"
=09elsif( the_date.hour > 12 )
=09=09nice_date +=3D ( the_date.hour-12 ).to_s + ":" + the_minute + "pm"
=09else
=09=09nice_date +=3D ( the_date.hour ).to_s + ":" + the_minute + "pm"
=09end
=09nice_date
end
#Woah, ugly.
#Anyone spare a moment to show me the right way to do something like this?
#Thanks in advance
#-Harold
DateTime.now.to_s stored away.
When I'm reading them out, and showing them to the user I want to see
something pretty like:
Sat Mar 10 at 12:34pm
Heres the code I came up with:
def timeFormat( in_str )
=09the_date =3D DateTime.parse( in_str )
=09the_date =3D the_date.new_offset( -7.0/24.0 )
=09nice_date =3D ''
=09nice_date +=3D case the_date.cwday
=09=09when 1; "Mon "
=09=09when 2; "Tue "
=09=09when 3; "Wed "
=09=09when 4; "Thu "
=09=09when 5; "Fri "
=09=09when 6; "Sat "
=09=09when 7; "Sun "
=09end
=09nice_date +=3D case the_date.month
=09=09when 1; "Jan "
=09=09when 2; "Feb "
=09=09when 3; "Mar "
=09=09when 4; "Apr "
=09=09when 5; "May "
=09=09when 6; "Jun "
=09=09when 7; "Jul "
=09=09when 8; "Aug "
=09=09when 9; "Sep "
=09=09when 10; "Oct "
=09=09when 11; "Nov "
=09=09when 12; "Dec "
=09end
=09nice_date +=3D the_date.day.to_s + ' at '
=09the_minute =3D the_date.min
=09if( the_minute < 10 )
=09=09the_minute =3D "0"+the_minute.to_s
=09else
=09=09the_minute =3D the_minute.to_s
=09end
=09if( the_date.hour < 12 )
=09=09nice_date +=3D the_date.hour.to_s + ":" + the_minute + "am"
=09elsif( the_date.hour > 12 )
=09=09nice_date +=3D ( the_date.hour-12 ).to_s + ":" + the_minute + "pm"
=09else
=09=09nice_date +=3D ( the_date.hour ).to_s + ":" + the_minute + "pm"
=09end
=09nice_date
end
#Woah, ugly.
#Anyone spare a moment to show me the right way to do something like this?
#Thanks in advance
#-Harold