Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Change periods of the day replacements to be case-sensitive #7

Merged
merged 2 commits into from
Jul 26, 2024

Conversation

edmocosta
Copy link
Collaborator

The Go time parsing requires the period of the day value and the layout element to be in the same letter case.
For example, If pm in lower case is used as template, it expects the value to be also in lower case (am, pm), otherwise an error will be returned by the time.Parse functions.

This PR changes lunes to replace the day periods elements respecting the define layout case, for example:

layout: January 02 Monday, 2006, 03:04:05 pm
value: Febrero 25 jueves, 1993, 02:03:04 a.m.
lang: es-ES

Before this change, it would translate the value to February 25 Thursday, 1993, 02:03:04 AM (upper case AM), which would fail to parse using the time.Parse:

val, _ := lunes.Translate("January 02 Monday, 2006, 03:04:05 pm", "Febrero 25 jueves, 1993, 02:03:04 a.m.", "es-ES")

// it returns an error, as the "AM" value cannot be parsed as a "pm" layout element. 
time.Parse("January 02 Monday, 2006, 03:04:05 pm", val)

With this PR changes, the case is maintained, and the same Translate function call will return February 25 Thursday, 1993, 02:03:04 am (lower case am), making the time.Parse function work as exptected.

--

Note: The locale translations lookup for periods of the day are still being compared using case-insensitive, it didn't change. the only thing that was changed is the layout element replacement (AM, PM), that are now replaced using the same layout letter case.

@edmocosta edmocosta requested a review from a team as a code owner July 25, 2024 16:17
@edmocosta edmocosta requested a review from jsvd July 26, 2024 08:43
Copy link
Member

@jsvd jsvd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@edmocosta edmocosta merged commit 5771bab into main Jul 26, 2024
2 checks passed
@edmocosta edmocosta deleted the make-day-periods-case-sensitive branch July 26, 2024 09:45
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants