ruby on rails - week_field gives wrong week after serialization and deserialization -


I am using the week_field assistant to generate a week's picker in a form. When I select a week and submit it, my controller gets the correct sequential week (like '2014-W03'), which I can convert to a date object. It all works, but when the date is released again, it always gets less than 1 (as it would be '2014-W02').

  def format_date (value) value.try (: strftime, "% yw% w")  

serializes and it does not seem encoding when the date is parsed. In addition, parsing is followed and serialized on this date which is eaten for this unsuccessful result:

  irb> date. PRSE ('2014-W03'). Strawptime ('% w-w% w') = & gt; "2014-W02"  

Any thoughts that are happening here or how can I understand how it can be done? I hate to make an extra +1 at number of weeks or if there is a cleaner path, change the week_field format_date definition

with:

 % w - week number of the year . Week starts with Monday (00..53)  

It seems that you have a good old age - start with 0 or start with 1 - problem

 % g - week based year% g - last 2 digits (00..99)% v - week number based on week (01..53) < / Code> 

Comments

Popular posts from this blog

apache - 504 Gateway Time-out The server didn't respond in time. How to fix it? -

c# - .net WebSocket: CloseOutputAsync vs CloseAsync -

c++ - How to properly scale qgroupbox title with stylesheet for high resolution display? -