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
Add timezone support to Clock component #1966
base: ucr
Are you sure you want to change the base?
Conversation
Can one of the admins verify this patch? |
appinventor/components/src/com/google/appinventor/components/runtime/Clock.java
Outdated
Show resolved
Hide resolved
@ewpatton totally forgot about this PR in the meetup. The only missing block I think that this PR need is a "getTimezones" that returns a List of all available timezones. |
*/ | ||
@SimpleFunction(description = "Updates the timezone in which the instant is saved at") | ||
public static Calendar ChangeTimezone(Calendar instant, String timezone) { | ||
if (timezones.contains(timezone)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestion: trim spaces and ignore case in comparison. If found, then use the actual value that is in the list (not the passed-in parameter) and set the timezone to the found-value
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is case-sensitive, that's why I mentioned:
If found, then use the actual value that is in the list (not the passed-in parameter) and set the timezone to the found-value
If a user wants, for example, america/detroit (and not America/Detroit), they should use the following procedure:
That is how a normal developer would do, as the block is just calling the native method. We're not making conversions or any other work inside/with it, as we would be making suppositions of what a user might want. If a user sees a procedure of "getTimezoneCaseInsensitive" made with blocks, they will gain the logic of how it can be done. Instead, if we give them already done, we are restricting the possibilities (and such procedure can be done quite easily with blocks, without needing us to make assumptions). That's my opinion, but I think the block should call the method without applying conversions or anything. |
Well, they could always learn Java. That gives them much more opportunity than App Inventor. 😄 One of the goals with App Inventor is to make hard stuff easier. I think allowing one to set the timezone using a case insensitive string fits within that directive. I expect that in other apps students will have plenty of opportunity to learn how to use the upper/lower case blocks. I'm not convinced there isn't any reason to make a component purposefully "dumber" about something. Timezones are already a challenging enough problem without also introducing things like case sensitivity into it. |
Yeah, that's totally right. But what I mean is that, if we make assumptions, we will have to make sure that those assumptions will never cause conflicts with what the user really wants. That was my concern. Just an example of what worries me. JavaScript is a very weird language, it behaves in really strange manners, like
Well, you are right, I haven't thought about it like that. 😓
Then I will tweak it so it becomes case-insensitive. However, it would be easier if Java just accepted the lower case one ( |
Should be now fixed. It now first checks if it matches the equal timezone, and if not it checks if it matches the case-insensitive one. If it does, it re-runs the method but with the correct timezone. |
@barreeeiroo It looks like you missed an import when you did the merge. |
My bad. It should be now fixed. 🤦♂ |
This PR adds the ability to play with timezones in which components are stored at