use of java.util.Calendar in project dropwizard by dropwizard.
the class JodaDateTimeArgument method apply.
@Override
public void apply(final int position, final PreparedStatement statement, final StatementContext ctx) throws SQLException {
if (value != null) {
if (calendar.isPresent()) {
// We need to make a clone, because Calendar is not thread-safe
// and some JDBC drivers mutate it during time calculations
final Calendar calendarClone = (Calendar) calendar.get().clone();
statement.setTimestamp(position, new Timestamp(value.getMillis()), calendarClone);
} else {
statement.setTimestamp(position, new Timestamp(value.getMillis()));
}
} else {
statement.setNull(position, Types.TIMESTAMP);
}
}
use of java.util.Calendar in project dropwizard by dropwizard.
the class ZonedDateTimeArgument method apply.
@Override
public void apply(final int position, final PreparedStatement statement, final StatementContext ctx) throws SQLException {
if (value != null) {
if (calendar.isPresent()) {
// We need to make a clone, because Calendar is not thread-safe
// and some JDBC drivers mutate it during time calculations
final Calendar calendarClone = (Calendar) calendar.get().clone();
statement.setTimestamp(position, new Timestamp(value.toInstant().toEpochMilli()), calendarClone);
} else {
statement.setTimestamp(position, new Timestamp(value.toInstant().toEpochMilli()));
}
} else {
statement.setNull(position, Types.TIMESTAMP);
}
}
use of java.util.Calendar in project dropwizard by dropwizard.
the class InstantArgumentTest method applyCalendar.
@Test
public void applyCalendar() throws Exception {
final ZoneId systemDefault = ZoneId.systemDefault();
// this test only asserts that a calendar was passed in. Not that the JDBC driver
// will do the right thing and adjust the time.
final ZonedDateTime zonedDateTime = ZonedDateTime.parse("2012-12-21T00:00:00.000Z");
final ZonedDateTime expected = zonedDateTime.withZoneSameInstant(systemDefault);
final Calendar calendar = new GregorianCalendar(TimeZone.getTimeZone(systemDefault));
new InstantArgument(zonedDateTime.toInstant(), Optional.of(calendar)).apply(1, statement, context);
Mockito.verify(statement).setTimestamp(1, Timestamp.from(expected.toInstant()), calendar);
}
use of java.util.Calendar in project Meizhi by drakeet.
the class Dates method isTheSameDay.
public static boolean isTheSameDay(Date one, Date another) {
Calendar _one = Calendar.getInstance();
_one.setTime(one);
Calendar _another = Calendar.getInstance();
_another.setTime(another);
int oneDay = _one.get(Calendar.DAY_OF_YEAR);
int anotherDay = _another.get(Calendar.DAY_OF_YEAR);
return oneDay == anotherDay;
}
use of java.util.Calendar in project Meizhi by drakeet.
the class Dates method toDate.
public static String toDate(Date date, int add) {
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
calendar.add(Calendar.DATE, add);
return toDate(calendar.getTime());
}
Aggregations