Package org.gedcomx.date
Class GedcomxDateUtil
- java.lang.Object
-
- org.gedcomx.date.GedcomxDateUtil
-
public class GedcomxDateUtil extends Object
Static utility functions for handling GedcomX Dates- Author:
- John Clark.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static classGedcomxDateUtil.DateA simplified representation of a date.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static GedcomxDateSimpleaddDuration(GedcomxDateSimple startDate, GedcomxDateDuration duration)Add a duration to a simple datestatic intdaysInMonth(Integer month, Integer year)Find the number of days in a month within a given yearstatic GedcomxDateDurationgetDuration(GedcomxDateSimple startDate, GedcomxDateSimple endDate)Calculates the Duration between two datesstatic GedcomxDateRangejavaDatesToGedcomxDateRange(Date fromDate, Date toDate)Converts two java.util.Date objects to a GedcomxDateRange object.static GedcomxDateSimplejavaDateToGedcomxDateSimple(Date javaDate)Converts a java.util.Date to a GedcomxDate object.static GedcomxDateDurationmultiplyDuration(GedcomxDateDuration duration, int multiplier)Multiple a duration by a fixed numberstatic GedcomxDateparse(String date)Parse a String representation of a Formal GedcomX Dateprotected static voidzipDates(GedcomxDateUtil.Date start, GedcomxDateUtil.Date end)Ensures that both start and end have values where the other has values.protected static voidzipDuration(GedcomxDateUtil.Date date, GedcomxDateDuration duration)Ensures that date has its properties initialized based on what the duration has.
-
-
-
Method Detail
-
parse
public static GedcomxDate parse(String date)
Parse a String representation of a Formal GedcomX Date- Parameters:
date- The GedcomX Date- Returns:
- A GedcomxDate
-
getDuration
public static GedcomxDateDuration getDuration(GedcomxDateSimple startDate, GedcomxDateSimple endDate)
Calculates the Duration between two dates- Parameters:
startDate- The start dateendDate- The end date- Returns:
- The duration
-
addDuration
public static GedcomxDateSimple addDuration(GedcomxDateSimple startDate, GedcomxDateDuration duration)
Add a duration to a simple date- Parameters:
startDate- The date to start fromduration- The duration to add- Returns:
- a new simple date
-
multiplyDuration
public static GedcomxDateDuration multiplyDuration(GedcomxDateDuration duration, int multiplier)
Multiple a duration by a fixed number- Parameters:
duration- The duration to multiplymultiplier- The amount to multiply by- Returns:
- The new, multiplied duration
-
daysInMonth
public static int daysInMonth(Integer month, Integer year)
Find the number of days in a month within a given year- Parameters:
month- The monthyear- The year- Returns:
- The number of days in the month
-
zipDates
protected static void zipDates(GedcomxDateUtil.Date start, GedcomxDateUtil.Date end)
Ensures that both start and end have values where the other has values. For example, if start has minutes but end does not, this function will initialize minutes in end.- Parameters:
start- The start dateend- The end date
-
zipDuration
protected static void zipDuration(GedcomxDateUtil.Date date, GedcomxDateDuration duration)
Ensures that date has its properties initialized based on what the duration has. For example, if date does not have minutes and duration does, this will initialize minutes in the date.- Parameters:
date- The start dateduration- The duration
-
javaDateToGedcomxDateSimple
public static GedcomxDateSimple javaDateToGedcomxDateSimple(Date javaDate)
Converts a java.util.Date to a GedcomxDate object. The returned GedcomxDate will always be represented as UTC since java.util.Date does not have locale information and is defaulted to represent UTC.- Parameters:
javaDate- The java.util.Date object to convert.- Returns:
- a GedcomxDate representing the CE javaDate.
-
javaDatesToGedcomxDateRange
public static GedcomxDateRange javaDatesToGedcomxDateRange(Date fromDate, Date toDate)
Converts two java.util.Date objects to a GedcomxDateRange object. If toDate is null then the GedcomxDateRange will be an open-ended range. The fromDate and toDate will both be UTC since that is what a java.util.Date object represents.- Parameters:
fromDate- the start of the range. This cannot be null.toDate- the end of the range. This may be null.- Returns:
- a GedcomxDateRange that represents the range between the fromDate and toDate
- Throws:
GedcomxDateException- if fromDate is null.
-
-