< prev index next >

src/com/sun/org/apache/xerces/internal/jaxp/datatype/XMLGregorianCalendarImpl.java

Print this page


   1 /*
   2  * Copyright (c) 2004, 2006, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


2654             result = TimeZone.getDefault();
2655         } else {
2656             // zoneoffset is in minutes. Convert to custom timezone id format.
2657             char sign = zoneoffset < 0 ? '-' : '+';
2658             if (sign == '-') {
2659                 zoneoffset = -zoneoffset;
2660             }
2661             int hour = zoneoffset / 60;
2662             int minutes = zoneoffset - (hour * 60);
2663 
2664             // Javadoc for java.util.TimeZone documents max length
2665             // for customTimezoneId is 8 when optional ':' is not used.
2666             // Format is
2667             // "GMT" ('-'|''+') (digit digit?) (digit digit)?
2668             //                   hour          minutes
2669             StringBuffer customTimezoneId = new StringBuffer(8);
2670             customTimezoneId.append("GMT");
2671             customTimezoneId.append(sign);
2672             customTimezoneId.append(hour);
2673             if (minutes != 0) {



2674                 customTimezoneId.append(minutes);
2675             }
2676             result = TimeZone.getTimeZone(customTimezoneId.toString());
2677         }
2678         return result;
2679     }
2680 
2681     /**
2682      * <p>Creates and returns a copy of this object.</p>
2683      *
2684      * @return copy of this <code>Object</code>
2685      */
2686    public Object clone() {
2687         // Both this.eon and this.fractionalSecond are instances
2688         // of immutable classes, so they do not need to be cloned.
2689        return new XMLGregorianCalendarImpl(getEonAndYear(),
2690                         this.month, this.day,
2691                         this.hour, this.minute, this.second,
2692                         this.fractionalSecond,
2693                         this.timezone);


   1 /*
   2  * Copyright (c) 2004, 2016, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


2654             result = TimeZone.getDefault();
2655         } else {
2656             // zoneoffset is in minutes. Convert to custom timezone id format.
2657             char sign = zoneoffset < 0 ? '-' : '+';
2658             if (sign == '-') {
2659                 zoneoffset = -zoneoffset;
2660             }
2661             int hour = zoneoffset / 60;
2662             int minutes = zoneoffset - (hour * 60);
2663 
2664             // Javadoc for java.util.TimeZone documents max length
2665             // for customTimezoneId is 8 when optional ':' is not used.
2666             // Format is
2667             // "GMT" ('-'|''+') (digit digit?) (digit digit)?
2668             //                   hour          minutes
2669             StringBuffer customTimezoneId = new StringBuffer(8);
2670             customTimezoneId.append("GMT");
2671             customTimezoneId.append(sign);
2672             customTimezoneId.append(hour);
2673             if (minutes != 0) {
2674                 if (minutes < 10) {
2675                     customTimezoneId.append('0');
2676                 }
2677                 customTimezoneId.append(minutes);
2678             }
2679             result = TimeZone.getTimeZone(customTimezoneId.toString());
2680         }
2681         return result;
2682     }
2683 
2684     /**
2685      * <p>Creates and returns a copy of this object.</p>
2686      *
2687      * @return copy of this <code>Object</code>
2688      */
2689    public Object clone() {
2690         // Both this.eon and this.fractionalSecond are instances
2691         // of immutable classes, so they do not need to be cloned.
2692        return new XMLGregorianCalendarImpl(getEonAndYear(),
2693                         this.month, this.day,
2694                         this.hour, this.minute, this.second,
2695                         this.fractionalSecond,
2696                         this.timezone);


< prev index next >