This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public boolean isOverLap(Date now, Date periodFrom, Date periodTo) { | |
//nullの場合は常に成立するよう最小値 | |
DateTime from = periodFrom == null ? new DateTime(0) : new DateTime(periodFrom); | |
//nullの場合は常に成立するよう最大値 | |
DateTime to = periodTo == null ? new DateTime(Long.MAX_VALUE) : new DateTime(periodTo); | |
Interval base = new Interval(new DateTime(now), new DateTime(now)); | |
Interval interval = new Interval(from, to); | |
//以上、以下でtrueにする場合abuts()が必要 overlaps()だけだと未満、超 | |
return interval.abuts(base) || interval.overlaps(base); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//java.util.Dateなどで初期化 | |
LocalDate start = new LocalDate(...); | |
LocalDate end = new LocalDate(...); | |
// 日か月か年がstart < end の場合はtrue | |
Logger.debug("before? %s", start.isBefore(end)); | |
// 日か月か年がstartとendで違ってればtrue | |
Logger.debug("not equal? %s", !start.equals(end)); | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DateTime start = ... //期間はじまり | |
DateTime end = ... //期間おわり | |
Logger.debug("between:%s", Days.daysBetween(start, end).getDays()); | |
//日付をまたいでも、24時間以上離れていない場合はゼロになる |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//commons-langのDateutilsを使った方がラク | |
DateTime dt = DateTimeFormat.forPattern("yyyy/MM/dd HH:mm:ss").parseDateTime(string) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DateMidnight dm = new DateMidnight(new Date()); | |
Logger.debug("%s", dm.toString("yyyy-MM-dd HH:mm:ss")); //2012-02-27 00:00:00 のようなデータ | |
insertDababase(dm); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DateTime dt = new DateTime().withMonthOfYear(2); //今年の2月 | |
Logger.debug("月の最終日 %s", dt.dayOfMonth().getMaximumValue()); | |
Logger.debug("年の最終週 %s", dt.weekOfWeekyear().getMaximumValue()); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DateMidnight monthMidnight = new DateMidnight(year, month, 1); //指定月の1日 | |
Date to = monthMidnight.toDate(); | |
Date from = monthMidnight.minusMonths(1).toDate(); //指定月の先月 | |
Logger.debug("今月 %s", monthMidnight.toString("yyyy-MM-dd HH:mm:ss")); | |
Logger.debug("先月 %s", monthMidnight.minusMonths(1).toString("yyyy-MM-dd HH:mm:ss")); | |
searchDataBaseByMonthRange(from, to); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DateMidnight today = new DateMidnight(); //今日の0時を取得 | |
DateMidnight yesterday = today.minusDays(1); //昨日の0時を取得 | |
searchDatabaseRange(yesterday, today); //from, toに指定 | |
Logger.debug("from:%s to:%s", today.toString("yyyy-MM-dd HH:mm:ss"), | |
yesterday.toString("yyyy-MM-dd HH:mm:ss")); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.hibernate.ScrollableResults; | |
import org.hibernate.ejb.QueryImpl; | |
import play.db.jpa.JPA; | |
public static void executeManyData() { | |
QueryImpl<ManyData> q = (QueryImpl<ManyData>)em().createQuery( | |
"from " + ManyData.class.getName() + " where 0 = 0"); | |
q.getHibernateQuery().setFetchSize(Integer.MIN_VALUE); |