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 a standard string conversion for Civil type #6137

Closed
dinukaamarasinghe817 opened this issue Mar 5, 2024 · 1 comment
Closed

Add a standard string conversion for Civil type #6137

dinukaamarasinghe817 opened this issue Mar 5, 2024 · 1 comment
Labels
module/time Reason/EngineeringMistake The issue occurred due to a mistake made in the past. Type/Bug

Comments

@dinukaamarasinghe817
Copy link
Contributor

Description:
Need to provide standards methods to convert a time:Civil value to a string value and a string value to a time:Civil value with utcOffset and timeAbbrev

Steps to reproduce:

  1. Create a time:Civil value with a utcfOffset and a timeAbbrev
  2. Convert the time:Civil value to a string using time:civilToString method
  3. Conver the converted string value back to a time:Civil value using time:civilFromString method
  4. Final value is not equivalent to the previous original value.

Affected modules

@TharmiganK
Copy link
Contributor

Tried the following sample with the latest Ballerina version(2201.10.0) and it is working as expected:

public function main() returns error? {
    time:Civil civil1 = {
        year: 2022,
        month: 1,
        day: 29,
        hour: 22,
        minute: 48,
        second: 0,
        timeAbbrev: "Asia/Colombo",
        utcOffset: {hours: 5, minutes: 30}
    };
    string civilString = check time:civilToString(civil1);
    io:println("Civil Time string: ", civil1);
    time:Civil civil2 = check time:civilFromString(civilString);
    io:println("Civil Time 1: ", civil1);
    io:println("Civil Time 2: ", civil2);
}
$ bal run
Compiling source
        tharmigan/zone_bbe:0.1.0

Running executable

Civil Time string: {"utcOffset":{"hours":5,"minutes":30},"timeAbbrev":"Asia/Colombo","year":2022,"month":1,"day":29,"hour":22,"minute":48,"second":0}
Civil Time 1: {"utcOffset":{"hours":5,"minutes":30},"timeAbbrev":"Asia/Colombo","year":2022,"month":1,"day":29,"hour":22,"minute":48,"second":0}
Civil Time 2: {"utcOffset":{"hours":5,"minutes":30},"timeAbbrev":"+05:30","dayOfWeek":6,"year":2022,"month":1,"day":29,"hour":22,"minute":48}

This is fixed with #6986

@TharmiganK TharmiganK added the Reason/EngineeringMistake The issue occurred due to a mistake made in the past. label Sep 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
module/time Reason/EngineeringMistake The issue occurred due to a mistake made in the past. Type/Bug
Projects
Status: Done
Development

No branches or pull requests

3 participants