-
-
Notifications
You must be signed in to change notification settings - Fork 52
Open
Description
下記のようなコードを書いた場合、23:59:59からの1秒間のデータを取得できない。
NSDate *startDate = [date dateAtStartOfDay];
NSDate *endDate = [date dateAtEndOfDay];
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"date >= %@ and date < %@", startDate, endDate];
// この後 predicate を使ってデータベース等に検索する
下記のようなコードを書くのが正しい。
NSDate *startDate = [date dateAtStartOfDay];
NSDate *endDate = [[date dateByAddingDays:1] dateAtStartOfDay];
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"date >= %@ and date < %@", startDate, endDate];
// この後 predicate を使ってデータベース等に検索する
より正しいコードを書くことに導くため、dateAtEndOfDayを廃止し dateAtStartOfNextDay を追加することが適切だと思われる。
azu
Metadata
Metadata
Assignees
Labels
No labels