Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dateAtEndOfDay を廃止する #36

Open
akuraru opened this issue Dec 14, 2015 · 0 comments
Open

dateAtEndOfDay を廃止する #36

akuraru opened this issue Dec 14, 2015 · 0 comments

Comments

@akuraru
Copy link
Collaborator

akuraru commented Dec 14, 2015

下記のようなコードを書いた場合、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 を追加することが適切だと思われる。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant