Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upNo Bug: Use Calendar's api to calculate DAU pings. #796
Conversation
| let monthly = pings.first(where: { $0 == .monthly }) | ||
|
|
||
| // No changes, no ping | ||
| if daily == nil && weekly == nil && monthly == nil { |
This comment has been minimized.
This comment has been minimized.
| } | ||
|
|
||
| private func getPings(forDate date: Date, lastPingDate: Date) -> [PingType] { | ||
| let calendar = DAU.calendar as Calendar |
This comment has been minimized.
This comment has been minimized.
| let monthly = pings.first(where: { $0 == .monthly }) | ||
|
|
||
| // No changes, no ping | ||
| if daily == nil && weekly == nil && monthly == nil { |
This comment has been minimized.
This comment has been minimized.
| return nil | ||
| } | ||
|
|
||
| return dauParams(daily, weekly, monthly) | ||
| return dauParams(daily != nil, weekly != nil, monthly != nil) |
This comment has been minimized.
This comment has been minimized.
jhreis
Jan 25, 2019
Contributor
I think I'd have dauParams just take an array too, honestly, than no need for all the logic above.
| log.debug("Dau stat params, daily: \(daily), weekly: \(weekly), monthly:\(monthly), lastPingDate: \(lastPingDate)") | ||
| if !daily && !weekly && !monthly { | ||
| // No changes, no ping | ||
| let daily = pings.first(where: { $0 == .daily }) |
This comment has been minimized.
This comment has been minimized.
c8b059b
to
d01ee56
| func eraDayOrdinal(_ date: Date) -> Int? { | ||
| return calendar.ordinality(of: .day, in: .era, for: date) | ||
| } | ||
| func nextDateComponent(_ components: DateComponents) -> Date? { |
This comment has been minimized.
This comment has been minimized.
kylehickinson
Jan 25, 2019
Contributor
OCD nit:
| func nextDateComponent(_ components: DateComponents) -> Date? { | |
| func nextDate(matching components: DateComponents) -> Date? { |
|
You can fix my OCD nit or not doesn't matter |
| guard let mYear = mondayComponents.year, let mMonth = mondayComponents.month, let mDay = mondayComponents.day else { | ||
| log.error("First monday of the week components are nil") | ||
| return "" | ||
| if considerToday && calendar.component(.weekday, from: self) == weekday.rawValue { |
This comment has been minimized.
This comment has been minimized.
kylehickinson
Jan 25, 2019
Contributor
Considering this is an extension on Date which can be any date, couldn't calendar.component(.weekday, from: self) be any Monday and not be today?
This comment has been minimized.
This comment has been minimized.
iccub
Jan 25, 2019
Author
Contributor
I'm not sure if I understand you.
This can be any weekday, depending on what date we are going to pass and against which weekday we are comparing.
Should I make it more specific and hide behind private accessor?
This comment has been minimized.
This comment has been minimized.
kylehickinson
Jan 25, 2019
•
Contributor
Basically Im confused because you're saying "get me the next weekday and consider today" but there's no concept of what day "today" is -- is it just the receiver date? I.e.
If the receiver date/self is Friday the 18th but Today is Friday the 25th and you say "give me the next friday" considering today, it'll just give you Friday the 18th.
So to clarify it you would either have to change it to explicitly give what "Today" is, or instead just change the naming, so that instead of "Consider Today" it's "Consider this (self) date's weekday"
This comment has been minimized.
This comment has been minimized.
kylehickinson
Jan 25, 2019
Contributor
So yeah I don't think based on usage this is a problem because its always called on today, was just a bit confusing to understand when not paying attention to the call site/only paying attention to the fact that this is a method on any Date
This comment has been minimized.
This comment has been minimized.
| let daily = monthly || lastPingDay != currentDay | ||
| let daily = pings.contains(.daily) | ||
| let weekly = pings.contains(.weekly) | ||
| let monthly = pings.contains(.monthly) |
This comment has been minimized.
This comment has been minimized.
jhreis
Jan 25, 2019
Contributor
If putting into variables, place them right before their usage down in dauPings
iccub commentedJan 25, 2019
•
edited by jhreis
Credit for the
Calendarbased solution goes to @kylehickinsonSubmitter Checklist:
Fix #123: This fixes the shattered coffee cup!(orNo Bug: <message>if no relevant ticket)NSLocalizableString()Test Plan:
Screenshots:
Reviewer Checklist:
QA/(Yes|No)release-notes/(include|exclude)bug/enhancement