Skip to content

Commit

Permalink
Showing 1 changed file with 63 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -6,6 +6,42 @@
* Eclipse Public License version 1.0
* GNU General Public License version 2
* GNU Lesser General Public License version 2.1
*
* * Version: EPL 1.0/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Eclipse Public
* License Version 1.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.eclipse.org/legal/epl-v10.html
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* Copyright (C) 2001 Chad Fowler <chadfowler@chadfowler.com>
* Copyright (C) 2001-2004 Jan Arne Petersen <jpetersen@uni-bonn.de>
* Copyright (C) 2002 Benoit Cerrina <b.cerrina@wanadoo.fr>
* Copyright (C) 2002-2004 Anders Bengtsson <ndrsbngtssn@yahoo.se>
* Copyright (C) 2004 Joey Gibson <joey@joeygibson.com>
* Copyright (C) 2004 Charles O Nutter <headius@headius.com>
* Copyright (C) 2004 Stefan Matthias Aust <sma@3plus4.de>
* Copyright (C) 2006 Thomas E Enebo <enebo@acm.org>
* Copyright (C) 2006 Ola Bini <ola.bini@ki.se>
* Copyright (C) 2006 Miguel Covarrubias <mlcovarrubias@gmail.com>
* Copyright (C) 2009 Joseph LaFata <joe@quibb.org>
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the EPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the EPL, the GPL or the LGPL.
*/
package org.jruby.truffle.core.rubinius;

@@ -262,6 +298,15 @@ private DynamicObject buildTime(DynamicObject timeClass, int sec, int min, int h
throw new RaiseException(getContext().getCoreLibrary().argumentErrorOutOfRange(this));
}

DateTime dt = new DateTime(year, 1, 1, 0, 0, 0, 0, DateTimeZone.UTC);

dt = dt.plusMonths(month - 1)
.plusDays(mday - 1)
.plusHours(hour)
.plusMinutes(min)
.plusSeconds(sec)
.plusMillis( nsec / 1_000_000 );

final DateTimeZone zone;
final boolean relativeOffset;
DynamicObject zoneToStore;
@@ -271,7 +316,8 @@ private DynamicObject buildTime(DynamicObject timeClass, int sec, int min, int h
zoneToStore = nil();
} else if (utcoffset == nil()) {
zone = TimeZoneParser.parse(this, StringOperations.getString(getContext(), envZon));
final String zoneName = TimeZoneParser.getShortZoneName(new DateTime(year, month, mday, hour, min, sec), zone);
// TODO BJF 16-Feb-2016 verify which zone the following date time should be in
final String zoneName = TimeZoneParser.getShortZoneName( dt.withZoneRetainFields(zone), zone);
zoneToStore = createString(StringOperations.encodeRope(zoneName, UTF8Encoding.INSTANCE));
relativeOffset = false;
} else if (utcoffset instanceof Integer) {
@@ -291,14 +337,26 @@ private DynamicObject buildTime(DynamicObject timeClass, int sec, int min, int h
throw new UnsupportedOperationException(String.format("%s %s %s %s", isdst, fromutc, utcoffset, utcoffset.getClass()));
}

dt = dt.withZoneRetainFields(zone);

// Following if block copied over from RubyTime.java createTime method
// If we're at a DST boundary, we need to choose the correct side of the boundary
if (isdst != -1) {
final DateTime beforeDstBoundary = dt.withEarlierOffsetAtOverlap();
final DateTime afterDstBoundary = dt.withLaterOffsetAtOverlap();

final int offsetBeforeBoundary = zone.getOffset(beforeDstBoundary);
final int offsetAfterBoundary = zone.getOffset(afterDstBoundary);

// If the time is during DST, we need to pick the time with the highest offset
dt = offsetBeforeBoundary > offsetAfterBoundary ? beforeDstBoundary : afterDstBoundary;
}

if (isdst == -1) {
final DateTime dateTime = new DateTime(year, month, mday, hour, min, sec, nsec / 1_000_000, zone);
return allocateObjectNode.allocate(timeClass, dateTime, nsec % 1_000_000, zoneToStore, utcoffset, relativeOffset, fromutc);
return allocateObjectNode.allocate(timeClass, dt, nsec % 1_000_000, zoneToStore, utcoffset, relativeOffset, fromutc);
} else {
// TODO (pitr 26-Nov-2015): is this correct to create the DateTime without isdst application?
final DateTime dateTime = new DateTime(year, month, mday, hour, min, sec, nsec / 1_000_000, zone);
return allocateObjectNode.allocate(timeClass, dateTime, nsec % 1_000_000, zoneToStore, utcoffset, relativeOffset, fromutc);
return allocateObjectNode.allocate(timeClass, dt, nsec % 1_000_000, zoneToStore, utcoffset, relativeOffset, fromutc);
}
}

0 comments on commit 2951c36

Please sign in to comment.