On Wed, 11 Feb 2015 20:19:47 +0100 Ladislav Slezak <[email protected]> wrote:
> Dne 11.2.2015 v 18:18 Ancor Gonzalez Sosa napsal(a): > > While writing the YaST Journal module I faced a problem I'm not > > sure how to solve. I wanted to format a date here: > > https://github.com/ancorgs/yast-journal/blob/master/src/lib/systemd_journal/entry_presenter.rb#L49 > > > > I wanted to mimic the format used by journalctl itself, which in > > plain English would be "%b %d %H:%M:%S". The problem is that using > > %b is not i18n-friendly. Obviously the problem goes further, like > > those crazy US people writing Feb. 1st as 02/01/2015. :-) > > The problem is that the Ruby interpreter does not use the standard > glibc formatting function strftime() which does support localization. > > E.g. "%c" conversion specification in strftime() is rendered as "The > preferred date and time representation for the current locale." (see > "man strftime"). > > Unfortunately, the Ruby implementation uses hardcoded English format > for "%c" which does not allow localization, see [1]. > > It seems that plain Ruby does not support localization much, e.g. > even locale dependent string comparison is missing... > > > > In Rails the i18n gem is used. It offers an "localize" method that > > deals with date formatting > > http://www.rubydoc.info/github/svenfuchs/i18n/master/I18n/Backend/Base:localize > > > > But I don't know how to do it in YaST or if I'm the first one > > facing the problem. > > There are basically two possible solutions: > > - Run "date" command and format the time using the external program, > e.g.: > > SCR.Execute(path(".target.bash_output"), "date +%c -d '2015-01-28 > 13:54:42'") > > This is suitable just for few date values, starting a new subshell > for each date is quite ineffective. If you need to format many values > then save them to a file and use "-f" date option. > > > - Use strftime() call in a C Ruby extension. We already do this for > locale dependent string comparison, see Yast.strcoll() implementation > in ruby-bindings [2]. Similarly we can add a strftime() wrapper there. > > > The first solution is simpler but I'd rather prefer the second one as > it has lower overhead and scales better. > I agree, second solution should be quite easy to do and good solution. So if we agreed, I can add such method to Yast namespace. Josef > > > [1] > http://rxr.whitequark.org/mri/source/ext/date/date_strftime.c?v=2.1.2#217 > [2] > https://github.com/yast/yast-ruby-bindings/blob/master/src/binary/Builtin.cc#L627 > > > -- > > Best Regards > > Ladislav Slezák > Yast Developer > ------------------------------------------------------------------------ > SUSE LINUX, s.r.o. e-mail: > [email protected] Lihovarská 1060/12 tel: > +420 284 028 960 190 00 Prague 9 fax: > +420 284 028 951 Czech Republic > http://www.suse.cz/ -- To unsubscribe, e-mail: [email protected] To contact the owner, e-mail: [email protected]
