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

Convert to ISO8601 fix #9

Open
bittib010 opened this issue Sep 24, 2024 · 0 comments
Open

Convert to ISO8601 fix #9

bittib010 opened this issue Sep 24, 2024 · 0 comments

Comments

@bittib010
Copy link
Owner

Make it available from main converter script and replace with this as it also checks for current valid ISO format:

function Convert-ToISO8601Duration {
    param (
        [string]$timeValue
    )

    # Check if the input is already in a valid ISO 8601
    if ($timeValue -match '^P(\d+D)?(T(\d+H)?(\d+M)?)?$') {
        return $timeValue  # Return it as-is if it's already in ISO 8601 format
    }

    if ($timeValue -match '(\d+)([HMDhmd])') {
        $value = $matches[1]
        $unit = $matches[2].ToUpper()

        switch ($unit) {
            'H' { return "PT${value}H" }
            'M' { return "PT${value}M" } 
            'D' { return "P${value}D" } 
            default { return $timeValue } # In case of unrecognized format, return input as-is
        }
    }
    else {
        return $timeValue # return it unchanged if not meeting criterias
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant