nurkiewicz@gmail.com | @tnurkiewicz
2013-07-06T11:40:00.000Z
|
Calendar cal = new GregorianCalendar(2012, FEBRUARY, 29, 15, 0);
cal.add(YEAR, 1);
System.out.println(cal.getTime());
DateTime cal = new DateTime(2012, 2, 29, 15, 0, 0).AddYears(1);
Console.WriteLine(cal);
IllegalArgumentException
samcik.blox.pl/2012/03/Dzien-ktorego-nie-ma-Sprawdz-co-bank-wykreslil.html“[...] in accordance with Terms and Conditions [...] interest is paid for actual number of days funds were on account [...] however it is assumed that year consists of 365 days.
Year 2012 has 366 days, thus
interest is not paid for 29th of February.Yours faithfully, [some] Bank”
Integer.MAX_VALUE
)
|
|
java.util.Date
“A date in a calendar is a reference to a particular day represented within a calendar system. [...] A particular day may be represented by a different date in another calendar”
“The class Date
represents a specific instant in time, with millisecond precision.”
java.util.Timezone
Winter → Summer | Summer → Winter |
final TimeZone tz = TimeZone.getTimeZone("Europe/Warsaw");
TimeZone.getTimeZone("GMT+01:00");
TimeZone.getTimeZone("Europe/warsaw");
java.util.Calendar
def leapYear(year: Int): Boolean =
year % 4 == 0
def leapYear(year: Int): Boolean =
(year % 4 == 0 && year % 100 != 0) ||
(year % 400 == 0)
def leapYear(year: Int): Boolean =
new GregorianCalendar(year, JANUARY, 1).
getActualMaximum(DAY_OF_YEAR) > 365
Calendar c = Calendar.getInstance();
System.out.println(c.get(Calendar.YEAR));
$ java ...
2013
$ java -Duser.country=TH -Duser.language=th ...
2556
$ java -Duser.country=JP -Duser.language=ja -Duser.variant=JP ...
25
Calendar c = new GregorianCalendar();
Calendar c = new GregorianCalendar(timeZone);
Calendar c = new GregorianCalendar(timeZone, locale);
Date
vs. Calendar
?
final DateTime yearLater = new DateTime(2012, 2, 29, 15, 0).plusYears(1);
joda-time.sourceforge.net
import org.joda.time.DateTime;
import javax.xml.bind.DatatypeConverter;
public class XsdJodaTimeConverter {
public static DateTime unmarshal(String dateTime) {
final long millis = DatatypeConverter.
parseDate(dateTime).
getTimeInMillis();
return new DateTime(millis);
}
public static String marshal(DateTime calendar) {
return DatatypeConverter.printDate(
calendar.toGregorianCalendar()
);
}
}
.xjb
file
<bindings version="1.0" xmlns="http://java.sun.com/xml/ns/jaxb" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<globalBindings>
<javaType xmlType="xs:dateTime"
name="org.joda.time.DateTime"
parseMethod="XsdJodaTimeConverter.unmarshal"
printMethod="XsdJodaTimeConverter.marshal"/>
</globalBindings>
</bindings>
import org.joda.time.Instant;
import javax.persistence.AttributeConverter;
import javax.persistence.Converter;
import java.util.Date;
@Converter(autoApply = true)
public class JodaTimeConverter implements AttributeConverter<Instant, Date> {
@Override
public Date convertToDatabaseColumn(Instant attr) {
return attr != null? attr.toDate(): null;
}
@Override
public Instant convertToEntityAttribute(Date dbData) {
return dbData != null? new Instant(dbData): null;
}
}
Thread.sleep()
implicit override val generatorDrivenConfig =
PropertyCheckConfig(minSuccessful = 10000, workers = 4)
test("any date +1 year and -1 year should yield same date back") {
check {
random: Date => {
val plusMinusYear = new GregorianCalendar
plusMinusYear.setTime(random)
plusMinusYear.add(YEAR, 1)
plusMinusYear.add(YEAR, -1)
random == plusMinusYear.getTime
}
}
}
Falsified after 2665 passed tests:
arg0 = Mon Feb 29 03:21:22 CET 73843340
newTrigger()
.startAt(futureDate(1, YEAR))
.build();
quartz-scheduler.org/documentation/quartz-2.1.x/tutorials/tutorial-lesson-05
MessageProducer producer = session.createProducer(destination);
TextMessage message = session.createTextMessage("...hello, delayed!");
message.setLongProperty(ScheduledMessage.AMQ_SCHEDULED_DELAY, oneYearMillis);
producer.send(message);
http://activemq.apache.org/delay-and-schedule-message-delivery.html
(defn easter [year]
(let [
a (mod year 19)
b (Math/floor (/ year 100))
c (mod year 100)
d (Math/floor (/ b 4))
e (mod b 4)
f (Math/floor (/ (+ b 8) 25))
g (Math/floor (/ (inc (- b f)) 3))
h (mod (+ (- (+ (* 19 a) b) d g) 15) 30)
i (Math/floor (/ c 4))
k (mod c 4)
L (mod (- (+ 32 (* 2 e) (* 2 i)) h k) 7)
m (Math/floor (/ (+ a (* 11 h) (* 22 L)) 451))
n (- (+ h L 114) (* 7 m))
month (dec (Math/floor (/ n 31)))
day (inc (mod n 31))]
(java.util.GregorianCalendar. year month day)))
en.wikipedia.org/wiki/Computus