Skip to content
New issue

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

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

Already on GitHub? # to your account

Freeze bandwidth at point in time, display in correct time zone and u… #21

Merged
merged 1 commit into from
Jan 14, 2021

Conversation

oxtoacart
Copy link

@oxtoacart oxtoacart commented Jan 13, 2021

This corrects a few issues I found with #20.

  1. The expiration date needs to be evaluated from ttlSeconds immediately, otherwise it can drift over time
  2. The expiration date was showing an incorrect time because they were calculated as relative to GMT rather than relative to the system timezone. Expirations should be at midnight.
  3. The expiration date format was long and included seconds, which is unnecessarily precise.

This PR addresses those issues. After this PR, you can remove the convertTTSToDateTimeString from Utils.java in mobilesdk.

Copy link

@markhor-sarwar markhor-sarwar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Regarding 1, as far as I understand, bandwidth is a real time event. We don't cache the value of ttlSeconds and use it later, so it won't drift over time.

Anyway, I agree that evaluating the expires time immediately is a better solution. I'm just not sure if the drift over time issue is actually happening.

val expiresAtString: String

init {
val format = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I normally don't want to include UI logic in the model class, but I guess in this case it's worth it then.


init {
val format = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);
// the ttlSeconds from Go is relative to the system timezone, adjust accordingly for correct

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, not sure I fully understand this part. I thought ttlSeconds is the number of seconds remaining before the data cap is reset. If that's the case, ttlSeconds shouldn't be affected by the timezone right?

How does it work? Do we reset data for all users at the same time? Or do we reset data for each user independently depends on their timezone?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reset happens individually for each device (not exactly the same thing as user). Different devices will reset either daily, weekly or monthly, and they reset at midnight local time (based on the timezone that the application reported to our server).

I'm glad you asked - looks like there's actually a deeper error:

DEBUG flashlight.common: headers.go:55 omitting timezone header because: unable to find timezone for UTC (0)

So looks like the Go code is having trouble getting the timezone on Android.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here's the bug - golang/go#20455

I'll work on a workaround.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link

@markhor-sarwar markhor-sarwar Jan 14, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. If we always reset the data at midnight local time, on a specific day (depends on whether we reset the data daily, weekly or monthly), then why don't we just return the exact date instead of ttlSeconds?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In hindsight that might have been better. The implementation actually uses Redis TTL so what's stored is actually an expiration in seconds, not a date. It has to be converted to a date somewhere, so I chose to let the client do it rather than the server.

@oxtoacart
Copy link
Author

Regarding 1, as far as I understand, bandwidth is a real time event. We don't cache the value of ttlSeconds and use it later, so it won't drift over time.

Anyway, I agree that evaluating the expires time immediately is a better solution. I'm just not sure if the drift over time issue is actually happening.

True enough, still seems safest to evaluate this at construction time just in case.

@oxtoacart
Copy link
Author

Thanks @markhor-sarwar !

@oxtoacart oxtoacart merged commit 6e5a45c into markhor/issue4656 Jan 14, 2021
@oxtoacart oxtoacart deleted the ox/issue4656 branch January 14, 2021 19:35
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants