Coverage Report - ca.uhn.hl7v2.model.DataTypeUtil
 
Classes in this File Line Coverage Branch Coverage Complexity
DataTypeUtil
83%
10/12
75%
3/4
1.667
 
 1  
 /**
 2  
  * The contents of this file are subject to the Mozilla Public License Version 1.1
 3  
  * (the "License"); you may not use this file except in compliance with the License.
 4  
  * You may obtain a copy of the License at http://www.mozilla.org/MPL/
 5  
  * Software distributed under the License is distributed on an "AS IS" basis,
 6  
  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the
 7  
  * specific language governing rights and limitations under the License.
 8  
  *
 9  
  * The Original Code is "DataTypeUtil.java".  Description:
 10  
  * "This class is used to provide utility functions for other datatype classes and methods."
 11  
  *
 12  
  * The Initial Developer of the Original Code is University Health Network. Copyright (C)
 13  
  * 2001.  All Rights Reserved.
 14  
  *
 15  
  * Contributor(s): ______________________________________.
 16  
  *
 17  
  * Alternatively, the contents of this file may be used under the terms of the
 18  
  * GNU General Public License (the "GPL"), in which case the provisions of the GPL are
 19  
  * applicable instead of those above.  If you wish to allow use of your version of this
 20  
  * file only under the terms of the GPL and not to allow others to use your version
 21  
  * of this file under the MPL, indicate your decision by deleting  the provisions above
 22  
  * and replace  them with the notice and other provisions required by the GPL License.
 23  
  * If you do not delete the provisions above, a recipient may use your version of
 24  
  * this file under either the MPL or the GPL.
 25  
  *
 26  
  */
 27  
 
 28  
 package ca.uhn.hl7v2.model;
 29  
 
 30  
 import java.util.*;
 31  
 
 32  
 /**
 33  
  * This class is used to provide utility functions for other datatype classes and methods.
 34  
  */
 35  
 
 36  
 public class DataTypeUtil {
 37  
 
 38  0
     public DataTypeUtil() {
 39  0
     }
 40  
 
 41  
 
 42  
     /**
 43  
      * Preappend the zeros to the beginning of num such that the total length
 44  
      * equals totalDigitLength and return the string representation of the new number
 45  
      *
 46  
      * @param num              number
 47  
      * @param totalDigitLength number of digits
 48  
      * @return string representation of the new number
 49  
      */
 50  
     public static String preAppendZeroes(int num, int totalDigitLength) {
 51  79662
         return (totalDigitLength == 0) ?
 52  15
                 Integer.toString(num) :
 53  39816
                 String.format(String.format("%%0%dd", totalDigitLength), num);
 54  
     }
 55  
 
 56  
 
 57  
     /**
 58  
      * Return a signed four digit integer indicating the local
 59  
      * GMT offset. This is the HL7 Offset format in integer representation.
 60  
      *
 61  
      * @return a signed four digit integer indicating the local GMT offset
 62  
      */
 63  
     public static int getLocalGMTOffset() {
 64  10
         GregorianCalendar currentTime = new GregorianCalendar();
 65  10
         int gmtOffSet = currentTime.get(GregorianCalendar.ZONE_OFFSET);
 66  10
         int offSetSignInt = gmtOffSet < 0 ? -1 : 1;
 67  
         //get the absolute value of the gmtOffSet
 68  10
         int absGmtOffSet = Math.abs(gmtOffSet);
 69  10
         int gmtOffSetHours = absGmtOffSet / (3600 * 1000);
 70  10
         int gmtOffSetMin = (absGmtOffSet / 60000) % (60);
 71  
         // return the offset value HL7 format
 72  10
         return ((gmtOffSetHours * 100) + gmtOffSetMin) * offSetSignInt;
 73  
     }
 74  
 
 75  
 
 76  
 }
 77