JRuby

Make JRuby's Time#local behave more like MRI

Details

  • Type: Improvement Improvement
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: JRuby 1.1.6
  • Fix Version/s: JRuby 1.2
  • Component/s: Core Classes/Modules
  • Labels:
    None
  • Patch Submitted:
    Yes
  • Number of attachments :
    2

Description

Attached patch is a first attempt at making JRuby's Time#local behave more like MRI's.

Two functionality changes:

  • 7-arg version now behaves correctly around DST changes
  • 10-arg version now respects tz and isdst

More documentation and tests to follow.

  1. rubytime.patch
    18/Dec/08 9:26 PM
    8 kB
    Stephen Lewis
  2. rubytime-v2.patch
    19/Dec/08 9:59 AM
    9 kB
    Stephen Lewis

Activity

Hide
Stephen Lewis added a comment -

Attaching an updated version of the patch... all Rails' timezone-related tests now pass. The isdst flag on the 10-arg version now behaves as follows:

First case

  • if the local time described in the args to Time#local would ordinarily be subject to DST; and
  • if the isdst flag is not set

then

  • we look at the DST offset applied at the instant specified in the args to Time#local and reverse its effect
>> Time.local(0,30,1,1,10,2008,0,0,false,'Europe/London')
=> Wed Oct 01 02:30:00 +0100 2008

Second case

  • if the local time described in the args to Time#local would not ordinarily be subject to DST; and
  • if the isdst flag is set

then

  • we look at the DST offset specified just before the last DST to !DST transition and reverse its effect
>> Time.local(0,30,1,1,1,2008,0,0,true,'Europe/London')  
=> Tue Jan 01 00:30:00 +0000 2008

Third case

  • if the local time described in the args is an ambiguous wallclock time (e.g. in most timezones 01:30 on the day of a DST to !DST transition)

then

  • we honour the isdst flag to disambiguate the time
>> Time.local(0,30,1,26,10,2008,0,0,true,'Europe/London')
=> Sun Oct 26 01:30:00 +0100 2008
>> Time.local(0,30,1,26,10,2008,0,0,false,'Europe/London')
=> Sun Oct 26 01:30:00 +0000 2008
Show
Stephen Lewis added a comment - Attaching an updated version of the patch... all Rails' timezone-related tests now pass. The isdst flag on the 10-arg version now behaves as follows:

First case

  • if the local time described in the args to Time#local would ordinarily be subject to DST; and
  • if the isdst flag is not set
then
  • we look at the DST offset applied at the instant specified in the args to Time#local and reverse its effect
>> Time.local(0,30,1,1,10,2008,0,0,false,'Europe/London')
=> Wed Oct 01 02:30:00 +0100 2008

Second case

  • if the local time described in the args to Time#local would not ordinarily be subject to DST; and
  • if the isdst flag is set
then
  • we look at the DST offset specified just before the last DST to !DST transition and reverse its effect
>> Time.local(0,30,1,1,1,2008,0,0,true,'Europe/London')  
=> Tue Jan 01 00:30:00 +0000 2008

Third case

  • if the local time described in the args is an ambiguous wallclock time (e.g. in most timezones 01:30 on the day of a DST to !DST transition)
then
  • we honour the isdst flag to disambiguate the time
>> Time.local(0,30,1,26,10,2008,0,0,true,'Europe/London')
=> Sun Oct 26 01:30:00 +0100 2008
>> Time.local(0,30,1,26,10,2008,0,0,false,'Europe/London')
=> Sun Oct 26 01:30:00 +0000 2008
Hide
Charles Oliver Nutter added a comment -

Committed in r8846. Thank you for the patch! Rails guys will be happy

Show
Charles Oliver Nutter added a comment - Committed in r8846. Thank you for the patch! Rails guys will be happy

People

Vote (0)
Watch (1)

Dates

  • Created:
    Updated:
    Resolved: