pariyatti / mobile-app

The Pariyatti mobile app
https://pariyatti.app/
GNU Affero General Public License v3.0
8 stars 11 forks source link

Show daily cards locally, in the phone's current timezone #129

Closed deobald closed 4 months ago

deobald commented 1 year ago

After thinking about this for a bit, I realize it does pose some problems:

Assuming we don't bump the Kosa API version (and we shouldn't, for such a small non-breaking change), the Kosa API will serve all the old mobile app installs with the new data. If we release each day's cards as of "the earliest timezone" (UTC+14:00), most mobile app installs will see these cards very early on the previous day. On any given day, old apps will show tomorrow's data under "Today" at these times:

Kosa does not understand the user's timezone (nor should it), and for a wide variety of well-understood reasons, it is not an option to make Kosa's API timezone-aware. This change should exist only in the mobile app itself, since it's exclusively related to the phone or iPad's local timezone, but that means users with old version of the app are going to see weird data.

We probably want to be careful making this change, since it will definitely break old users and the mobile app has no way of requesting the user to upgrade yet.

The other problem I have with this change is that it's quite a divergence from what was requested and built back in January (see: https://github.com/pariyatti/kosa/issues/54). Rather than doing a large amount of work, only to undo or redo it a few months later, I propose we run a prioritization exercise to determine what work will be done on Kosa and the mobile app, how, and in what order.

deobald commented 5 months ago

I've started working on this change and thinking through how we can execute it in a way that both satisfies the requirement and leaves the code readable for future servers.

Regardless of how we choose to implement this feature, I'll reiterate that, once it's built, it will become impossible to diagnose discrepancies between the Perl scripts (email, RSS) and Kosa. The reason for this is that all the Perl script code (and current Kosa/Kosa2 code) is time-dependent, not date-dependent. The crux of all the difficulties highlighted in my previous comment is that times and dates are mathematically impossible to convert and compare. It is counter-intuitive, but a Date and a Time (or DateTime) belong to completely different number systems. The unfortunate truth of this number system incompatibility is that there is no meaning to "today" in Dates, absent a timezone. The concept of "today" only exists in Time.

As long as we remember this, and accept this limitation, the remaining decision is whether we want the new change to be friendlier to users or friendlier to future developers.

Option 1: Friendly to Users

User Outcome: Users see new cards as of 00:00 on "today's" date, in their respective timezone. Dev Outcome: The API will produce data that is hard to understand. published_date will return tomorrow's date, for most of the world, and published_at will return a time with today as a date component.

How it works: All DateTimes in Kosa2 are normalized to UTC, and will remain so. We would make a singular exception of one timezone-specific scheduled job, set to execute at 00:00 in UTC+12:00 (note: I'll strongly recommend UTC+12:00 instead of UTC+14:00 because the latter puts us two days into the future, which will be even more confusing). This is almost the earliest time, worldwide, and would allow all client phones in the west Pacific to see today's cards at 00:00 in their local time. Data would always look like this, for most of the world, on January 8th:

{ "published_date": "2024-01-08",
  "published_at": "2024-01-07T12:00:00Z" }

Unless we create a new "version 2" API endpoint, existing mobile app installs will see cards a day early in most of the world, until they update. We can release a "version 2" of the API, if we want.

Option 2: Friendly to Developers

User Outcome: Users see new cards as of 12:00 on "today's" date, in their respective timezone. Dev Outcome: The API will produce consistent data. published_date will be synchronized with published_at, because everything will operate in UTC.

How it works: All DateTimes in Kosa2 will still be UTC. We wouldn't make any exceptions for schedulers. As a result, the earliest we can run a job is at 00:00 in UTC. This would be at roughly noon (12:00) in the earliest timezone. To remain consistent, worldwide, we would make "today's" cards visible at noon in every timezone. Data would always look like this, for all of the world, on January 8th:

{ "published_date": "2024-01-08",
  "published_at": "2024-01-08T00:00:00Z" }

This approach still releases cards earlier than Kosa1 currently does in production, since it uses North American times. We could create a new "version 2" API, if we wanted to be pedantic, but this option releases cards "early" at 18:00 CST, which wouldn't be as disruptive if we don't create a v2 API.

Version 2 API

Creating a v2 API before we've even released an official 1.0 version of the software feels... weird... I guess. Doing things like that is usually a good sign we're polishing too much. That said, the software is live (and has been for a while), even if the 1.0 announcement hasn't been made on the mailing list. So perhaps I should think of the Pariyatti app as well into Version 1.0, in which case a corrective v2 API doesn't seem so crazy. Perhaps I'm obsessing over semantics. 😉

Please be aware that there won't be two sets of cards published, so the v1 API would still see cards early... but it would trim "tomorrow's" card from the feed, according to the old Perl/Kosa timezones (or UTC, if we'd prefer that).

Question

I realize neither of these options is ideal. I'm not wedded to either one, but I wanted to hear from you folks if you felt strongly about the various options at play:

Apologies if any of these explanations are confusing! Timezones are the worst. 😆

cc @brihas @balwa @nilendujani

brihas commented 5 months ago

Thanks, Steven.

That is very helpful.

Over the years, we've received feedback from users that they appreciate being able to start their day with that day's Daily Words of the Buddha. Of course, with our current system the date on those quotes is not also in sync with the user's timezone, and this is what we are trying to resolve. So, it should be available at 00:00 in their local timezone. Waiting to make it available until 12:00 is not desirable.

For the other two questions, I have no preferences and trust you to make the choice.

Best, Brihas

Brihas Sarathy Executive Director P A R I Y A T T I 867 Larmon Road, Onalaska, WA, 98570, USA Phone +1.541.719.8004 @.*** | www.pariyatti.org [image: Pariyatti logo] https://pariyatti.org

On Mon, Jan 8, 2024 at 11:37 AM Steven Deobald @.***> wrote:

I've started working on this change and thinking through how we can execute it in a way that both satisfies the requirement and leaves the code readable for future servers.

Regardless of how we choose to implement this feature, I'll reiterate that, once it's built, it will become impossible to diagnose discrepancies between the Perl scripts (email, RSS) and Kosa. The reason for this is that all the Perl script code (and current Kosa/Kosa2 code) is time-dependent, not date-dependent. The crux of all the difficulties highlighted in my previous comment is that times and dates are mathematically impossible to convert and compare. It is counter-intuitive, but a Date and a Time (or DateTime) belong to completely different number systems. The unfortunate truth of this number system incompatibility is that there is no meaning to "today" in Dates, absent a timezone. The concept of "today" only exists in Time.

As long as we remember this, and accept this limitation, the remaining decision is whether we want the new change to be friendlier to users or friendlier to future developers. Option 1: Friendly to Users

User Outcome: Users see new cards as of 00:00 on "today's" date, in their respective timezone. Dev Outcome: The API will produce data that is hard to understand. published_date will return tomorrow's date, for most of the world, and published_at will return a time with today as a date component.

How it works: All DateTimes in Kosa2 are normalized to UTC, and will remain so. We would make a singular exception of one timezone-specific scheduled job, set to execute at 00:00 in UTC+12:00 (note: I'll strongly recommend UTC+12:00 instead of UTC+14:00 because the latter puts us two days into the future, which will be even more confusing). This is almost the earliest time, worldwide, and would allow all client phones in the west Pacific to see today's cards at 00:00 in their local time. Data would always look like this, for most of the world, on January 8th:

{ "published_date": "2024-01-08", "published_at": "2024-01-09T12:00:00Z" }

Unless we create a new "version 2" API endpoint, existing mobile app installs will see cards a day early in most of the world, until they update. We can release a "version 2" of the API, if we want. Option 2: Friendly to Developers

User Outcome: Users see new cards as of 12:00 on "today's" date, in their respective timezone. Dev Outcome: The API will produce consistent data. published_date will be synchronized with published_at, because everything will operate in UTC.

How it works: All DateTimes in Kosa2 will still be UTC. We wouldn't make any exceptions for schedulers. As a result, the earliest we can run a job is at 00:00 in UTC. This would be at roughly noon (12:00) in the earliest timezone. To remain consistent, worldwide, we would make "today's" cards visible at noon in every timezone. Data would always look like this, for all of the world, on January 8th:

{ "published_date": "2024-01-08", "published_at": "2024-01-08T00:00:00Z" }

This approach still releases cards earlier than Kosa1 currently does in production, since it uses North American times. We could create a new "version 2" API, if we wanted to be pedantic, but this option releases cards "early" at 18:00 CST, which wouldn't be as disruptive if we don't create a v2 API. Version 2 API

Creating a v2 API before we've even released an official 1.0 version of the software feels... weird... I guess. Doing things like that is usually a good sign we're polishing too much. That said, the software is live (and has been for a while), even if the 1.0 announcement hasn't been made on the mailing list. So perhaps I should think of the Pariyatti app as well into Version 1.0, in which case a corrective v2 API doesn't seem so crazy. Perhaps I'm obsessing over semantics. 😉

Please be aware that there won't be two sets of cards published, so the v1 API would still see cards early... but it would trim "tomorrow's" card from the feed, according to the old Perl/Kosa timezones (or UTC, if we'd prefer that). Question

I realize neither of these options is ideal. I'm not wedded to either one, but I wanted to hear from you folks if you felt strongly about the various options at play:

  • Does anyone feel strongly about "today's" cards being visible at 00:00 vs. 12:00? (I would prefer if we at least kept this to a "round" time, though, and not 05:00 or some other arbitrary number.)
  • Does anyone feel strongly about published_date and published_time in the API being in/out of sync?
  • Does anyone feel strongly about whether we should create a v1 and v2 API, the first of which will trim "tomorrow's" cards off for European and American users with the old (current) app installed?

Apologies if any of these explanations are confusing! Timezones are the worst. 😆

cc @brihas https://github.com/brihas @balwa https://github.com/balwa @nilendujani https://github.com/nilendujani

— Reply to this email directly, view it on GitHub https://github.com/pariyatti/mobile-app/issues/129#issuecomment-1881707173, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAHIXKHH5GRUVNRBRV5GLKTYNRDGDAVCNFSM6AAAAAAWK7IV3SVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQOBRG4YDOMJXGM . You are receiving this because you were mentioned.Message ID: @.***>

deobald commented 5 months ago

Sounds good. To support existing app users in the least-fragile way possible, I suggest we publish cards as of 12:00 noon, UTC. This is 12 hours later than they are currently published, so users of the old app will have to wait 12 additional hours to see "today's" cards. We should do this because the current app lies about when it publishes cards, to maintain compatibility with the old PST (Perl) code. For example, it publishes in the first hour of a day, UTC, but says it published the card at 7:00am PST that same day (in the future). Correcting this is part of why we will not be able to reconcile with the old Perl script's output.

The only way for users to see cards appear at 00:00 in their local timezone is to publish cards at 12:00 in UTC, one day in advance. (Or at 00:00 in UTC+12:00, whichever way you'd prefer to look at it.) This will look very strange to anyone with the existing mobile app installed, so I suggest we build a v2 API.

Outcomes:

Optionally, we can consider publishing at 00:00 in UTC, rather than 12:00. We still need to publish +1 day in advance, so all the errors mentioned above will remain. I thought through this in the morning based on UTC+12:00 @ 00:00, but I don't see why the same solution couldn't work for UTC @ 00:00... at least not off the top of my head.

I'll proceed with this, assuming everyone is okay with these errors in the app that's currently in the App/Play Stores. But please do shout if either error is a concern for you. Thanks!

deobald commented 5 months ago

This work is now complete in the following 2 PRs:

I would like to sanity-check this work with @balwa before merging these, as this is quite a substantial change. Once these are merged and the Ops work is finished, we can deploy Kosa2 and then upgrade the mobile app.

balwa commented 5 months ago

Well, we could always nudge users of the older versions of the apps to upgrade to latest version. e.g https://pub.dev/packages/upgrader and https://pub.dev/packages/in_app_update [the latter is android specific]

deobald commented 5 months ago

Although we can do this, we can't do it to users of the current version of the mobile app... so it's likely anyone who upgrades to the "nudge" version will already have the new release anyway.

Still, it's something I'd like to include at some point. There's a card for this: https://github.com/pariyatti/mobile-app/issues/130

On Sun, 21 Jan 2024 at 06:02, Tanmay Balwa @.***> wrote:

Well, we could always nudge users of the older versions of the apps to upgrade to latest version. e.g https://pub.dev/packages/upgrader and https://pub.dev/packages/in_app_update [the latter is android specific]

— Reply to this email directly, view it on GitHub https://github.com/pariyatti/mobile-app/issues/129#issuecomment-1902639044, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAAE6OWCYDVUHCYLVO7RMJLYPUNW7AVCNFSM6AAAAAAWK7IV3SVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSMBSGYZTSMBUGQ . You are receiving this because you authored the thread.Message ID: @.***>