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

Unnecessary condition when Civil to Email string conversion with time:PREFER_TIME_ABBREV #2626

Closed
BuddhiWathsala opened this issue Jan 26, 2022 · 0 comments · Fixed by ballerina-platform/module-ballerina-time#411
Assignees
Labels
module/time Points/0.5 Team/DIU Data, IO, and Util packages related issues Type/Improvement

Comments

@BuddhiWathsala
Copy link
Contributor

Description:
When users specify time:PREFER_TIME_ABBREV, Civil to Email string conversion returned an error saying zone offset must not be null. But actually, the zone offset should be mandatory for time:PREFER_ZONE_OFFSET and time:ZONE_OFFSET_WITH_TIME_ABBREV_COMMENT.

The following sample returns the error.

import ballerina/time;
import ballerina/io;

public function main() {
    time:Zone? systemZone = time:getZone("Asia/Colombo");

    if systemZone is time:Zone {
        time:Civil civil = systemZone.utcToCivil(time:utcNow());
        io:println(time:civilToEmailString(civil, time:PREFER_TIME_ABBREV));
    }
}

Output

error FormatError ("civil.utcOffset must not be null")

Workaround until this is fixed.

import ballerina/time;
import ballerina/io;

public function main() {
    time:Zone? systemZone = time:getZone("Asia/Colombo");

    if systemZone is time:Zone {
        time:Civil civil = systemZone.utcToCivil(time:utcNow());
        civil.utcOffset = {hours: 0, minutes: 0};
        io:println(time:civilToEmailString(civil, time:PREFER_TIME_ABBREV));
    }
}

Output

Wed, 26 Jan 2022 12:36:25 +0530 (IST)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
module/time Points/0.5 Team/DIU Data, IO, and Util packages related issues Type/Improvement
Projects
None yet
1 participant