Coverage Report - net.objectlab.kit.datecalc.joda.JodaExcelDateUtil
 
Classes in this File Line Coverage Branch Coverage Complexity
JodaExcelDateUtil
85%
12/14
100%
6/6
2.5
 
 1  
 /*
 2  
  * ObjectLab, http://www.objectlab.co.uk/open is sponsoring the ObjectLab Kit.
 3  
  * 
 4  
  * Based in London, we are world leaders in the design and development 
 5  
  * of bespoke applications for the securities financing markets.
 6  
  * 
 7  
  * <a href="http://www.objectlab.co.uk/open">Click here to learn more</a>
 8  
  *           ___  _     _           _   _          _
 9  
  *          / _ \| |__ (_) ___  ___| |_| |    __ _| |__
 10  
  *         | | | | '_ \| |/ _ \/ __| __| |   / _` | '_ \
 11  
  *         | |_| | |_) | |  __/ (__| |_| |__| (_| | |_) |
 12  
  *          \___/|_.__// |\___|\___|\__|_____\__,_|_.__/
 13  
  *                   |__/
 14  
  *
 15  
  *                     www.ObjectLab.co.uk
 16  
  *
 17  
  * $Id: JodaExcelDateUtil.java 203 2006-10-11 12:53:07Z benoitx $
 18  
  *
 19  
  * Copyright 2006 the original author or authors.
 20  
  *
 21  
  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 22  
  * use this file except in compliance with the License. You may obtain a copy of
 23  
  * the License at
 24  
  *
 25  
  * http://www.apache.org/licenses/LICENSE-2.0
 26  
  *
 27  
  * Unless required by applicable law or agreed to in writing, software
 28  
  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 29  
  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 30  
  * License for the specific language governing permissions and limitations under
 31  
  * the License.
 32  
  */
 33  
 package net.objectlab.kit.datecalc.joda;
 34  
 
 35  
 import java.util.Calendar;
 36  
 
 37  
 import net.objectlab.kit.datecalc.common.ExcelDateUtil;
 38  
 
 39  
 import org.joda.time.DateTime;
 40  
 import org.joda.time.LocalDate;
 41  
 import org.joda.time.YearMonthDay;
 42  
 
 43  
 /**
 44  
  * Convert Excel Date to LocalDate, YearMonthDay or DateTime.
 45  
  * 
 46  
  * @author Benoit Xhenseval
 47  
  * @author $LastChangedBy: benoitx $
 48  
  * @version $Revision: 203 $ $Date: 2006-10-11 08:53:07 -0400 (Wed, 11 Oct 2006) $
 49  
  * 
 50  
  */
 51  
 public final class JodaExcelDateUtil {
 52  
 
 53  0
     private JodaExcelDateUtil() {
 54  0
     }
 55  
 
 56  
     public static LocalDate getLocalDate(final double date, final boolean use1904windowing) {
 57  16
         final Calendar c = ExcelDateUtil.getJavaCalendar(date, use1904windowing);
 58  
         
 59  16
         if (c == null) {
 60  2
             return null;
 61  
         }
 62  
         
 63  14
         return new LocalDate()
 64  
                 .withYear(c.get(Calendar.YEAR))
 65  
                 .withMonthOfYear(c.get(Calendar.MONTH) + 1)
 66  
                 .withDayOfMonth(c.get(Calendar.DAY_OF_MONTH));
 67  
     }
 68  
 
 69  
     // -----------------------------------------------------------------------
 70  
     //
 71  
     //    ObjectLab, world leaders in the design and development of bespoke 
 72  
     //          applications for the securities financing markets.
 73  
     //                         www.ObjectLab.co.uk
 74  
     //
 75  
     // -----------------------------------------------------------------------
 76  
 
 77  
     public static YearMonthDay getYearMonthDay(final double date, final boolean use1904windowing) {
 78  16
         final Calendar c = ExcelDateUtil.getJavaCalendar(date, use1904windowing);
 79  
         
 80  16
         if (c == null) {
 81  2
             return null;
 82  
         }
 83  
         
 84  14
         return new YearMonthDay(c.get(Calendar.YEAR), c.get(Calendar.MONTH) + 1, c.get(Calendar.DAY_OF_MONTH));
 85  
     }
 86  
 
 87  
     public static DateTime getDateTime(final double date, final boolean use1904windowing) {
 88  16
         final Calendar c = ExcelDateUtil.getJavaCalendar(date, use1904windowing);
 89  
         
 90  16
         if (c == null) {
 91  2
             return null;
 92  
         }
 93  
         
 94  14
         return new DateTime()
 95  
                 .withYear(c.get(Calendar.YEAR))
 96  
                 .withMonthOfYear(c.get(Calendar.MONTH) + 1)
 97  
                 .withDayOfMonth(c.get(Calendar.DAY_OF_MONTH))
 98  
                 .withMillisOfDay(0);
 99  
     }
 100  
 }
 101  
 
 102  
 /*
 103  
  * ObjectLab, http://www.objectlab.co.uk/open is sponsoring the ObjectLab Kit.
 104  
  * 
 105  
  * Based in London, we are world leaders in the design and development 
 106  
  * of bespoke applications for the securities financing markets.
 107  
  * 
 108  
  * <a href="http://www.objectlab.co.uk/open">Click here to learn more about us</a>
 109  
  *           ___  _     _           _   _          _
 110  
  *          / _ \| |__ (_) ___  ___| |_| |    __ _| |__
 111  
  *         | | | | '_ \| |/ _ \/ __| __| |   / _` | '_ \
 112  
  *         | |_| | |_) | |  __/ (__| |_| |__| (_| | |_) |
 113  
  *          \___/|_.__// |\___|\___|\__|_____\__,_|_.__/
 114  
  *                   |__/
 115  
  *
 116  
  *                     www.ObjectLab.co.uk
 117  
  */