-
Notifications
You must be signed in to change notification settings - Fork 66
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
Civil time offsets are not working properly. #2946
Comments
Explicitly updating the time abbreviation and time zone is not the way to shift a given timestamp to a new time zone. Here, when you change the time zone, it would mislead the |
Here, when you set the offset and time abbreviation manually on the civil value then it completely changes the time value. The You can do zone adjustments using the Zone APIs. For example: import ballerina/io;
import ballerina/time;
public function main() returns error? {
time:Utc utc1 = time:utcNow();
final string TIME_ZONE = "Asia/Colombo";
time:Zone? zone = time:getZone(TIME_ZONE);
if zone is time:Zone {
time:Civil timeInZone = zone.utcToCivil(utc1);
io:println("Time in " + TIME_ZONE + ": " + timeInZone.toString());
time:Utc utc2 = check zone.utcFromCivil(timeInZone);
// Both of the UTC times should be equal
io:println("UTC Time 1 : " + time:utcToEmailString(utc1));
io:println("UTC Time 2 : " + time:utcToEmailString(utc2));
} else {
io:println("Failed to load the time zone.");
}
} |
As @TharmiganK mentioned, if you need to convert UTC time to a different time zone, you must use the Zone APIs. We are adding a TimeZone example with the issue[1]. Hence, I am closing this issue. Please feel free to reopen if you need more help on the issue |
Description:
When following code snippet execute in the Ballerina Playground. It produce a incorrect time when the zone is adjusted.
Steps to reproduce:
The text was updated successfully, but these errors were encountered: