Home | History | Annotate | Download | only in asn1
      1 /*
      2  *  Licensed to the Apache Software Foundation (ASF) under one or more
      3  *  contributor license agreements.  See the NOTICE file distributed with
      4  *  this work for additional information regarding copyright ownership.
      5  *  The ASF licenses this file to You under the Apache License, Version 2.0
      6  *  (the "License"); you may not use this file except in compliance with
      7  *  the License.  You may obtain a copy of the License at
      8  *
      9  *     http://www.apache.org/licenses/LICENSE-2.0
     10  *
     11  *  Unless required by applicable law or agreed to in writing, software
     12  *  distributed under the License is distributed on an "AS IS" BASIS,
     13  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     14  *  See the License for the specific language governing permissions and
     15  *  limitations under the License.
     16  */
     17 
     18 /**
     19 * @author Stepan M. Mishura
     20 * @version $Revision$
     21 */
     22 
     23 package org.apache.harmony.security.asn1;
     24 
     25 import java.io.IOException;
     26 import java.util.Calendar;
     27 import java.util.GregorianCalendar;
     28 import java.util.TimeZone;
     29 
     30 
     31 /**
     32  * Abstract class to represent ASN.1 time types
     33  *
     34  * @see <a href="http://asn1.elibel.tm.fr/en/standards/index.htm">ASN.1</a>
     35  */
     36 
     37 public abstract class ASN1Time extends ASN1StringType {
     38 
     39     public ASN1Time(int tagNumber) {
     40         super(tagNumber);
     41     }
     42 
     43     @Override public Object getDecodedObject(BerInputStream in) throws IOException {
     44         GregorianCalendar c = new GregorianCalendar(TimeZone.getTimeZone("GMT"));
     45         c.set(Calendar.YEAR, in.times[0]);
     46         c.set(Calendar.MONTH, in.times[1]-1);
     47         c.set(Calendar.DAY_OF_MONTH, in.times[2]);
     48         c.set(Calendar.HOUR_OF_DAY, in.times[3]);
     49         c.set(Calendar.MINUTE, in.times[4]);
     50         c.set(Calendar.SECOND, in.times[5]);
     51         c.set(Calendar.MILLISECOND, in.times[6]);
     52         return c.getTime();
     53     }
     54 }
     55