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

Add timezone support to Clock component #1966

Open
wants to merge 19 commits into
base: ucr
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -22,9 +22,11 @@
import com.google.appinventor.components.runtime.util.ErrorMessages;


import java.util.Arrays;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.Date;
import java.util.TimeZone;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
Expand Down Expand Up @@ -605,6 +607,21 @@ public static String FormatTime(Calendar instant) {
return Dates.FormatTime(instant);
}

/**
* Changes the timezone of a given instant.
*
* @param instant : instant to modify
* @param timezone : timezone to apply to instant
* @return : updated instant
*/
@SimpleFunction(description = "Updates the timezone in which the instant is saved at")
public static Calendar ChangeTimezone(Calendar instant, String timezone) {
if (Arrays.asList(TimeZone.getAvailableIDs()).contains(timezone))
barreeeiroo marked this conversation as resolved.
Show resolved Hide resolved
return instant.setTimeZone(TimeZone.getTimeZone(timezone));
else
throw new YailRuntimeError("Your given timezone is not a valid timezone.");
}

@Override
public void onStop() {
onScreen = false;
Expand Down