Skip to content

Commit

Permalink
googleapis#3157 add methods toDate, fromDate
Browse files Browse the repository at this point in the history
  • Loading branch information
praful committed Nov 5, 2018
1 parent 9c111f4 commit 8127074
Showing 1 changed file with 34 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.threeten.bp.LocalDate;

/**
* Represents a Date without time, such as 2017-03-17. Date is timezone independent.
*/
Expand Down Expand Up @@ -68,7 +70,39 @@ public static Date parseDate(String date) {
int dayOfMonth = Integer.parseInt(matcher.group(3));
return new Date(year, month, dayOfMonth);
}

/**
* @param date
* @return LocalDate
*/
public static LocalDate toDate(Date date){
return LocalDate.of(date.year, date.month, date.dayOfMonth);
}

/**
* @param date
* @return Date
*/
public static Date toDate(LocalDate date){
return new Date(date.getDayOfYear(), date.getMonthValue(), date.getDayOfMonth());
}

/**
* @param date
* @return LocalDate
*/
public static LocalDate fromDate(Date date){
return LocalDate.of(date.year, date.month, date.dayOfMonth);
}

/**
* @param date
* @return Date
*/
public static Date fromDate(LocalDate date){
return new Date(date.getDayOfYear(), date.getMonthValue(), date.getDayOfMonth());
}

/** Returns the year. */
public int getYear() {
return year;
Expand Down

0 comments on commit 8127074

Please sign in to comment.