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

ICU-22991 Remove unnecessary overload in Calendar #3317

Merged
merged 1 commit into from
Dec 23, 2024

Conversation

FrankYFTang
Copy link
Contributor

@FrankYFTang FrankYFTang commented Dec 23, 2024

  1. Remove unnecessary call to setTimeInMillis(getNow(), success); in constructor except in GregorianCalendar because allother calendar are not public class and are created through the Calendar::createInstance() method and code in that method already call setTimeInMillis(getNow(), success);

Notice the Calendar API documentation states

"Like other locale-sensitive classes, Calendar provides a static method, createInstance, for getting a generally useful object of this type. Calendar's createInstance method returns the appropriate Calendar subclass whose time fields have been initialized with the current date and time:

Calendar *rightNow = Calendar::createInstance(errCode);
"

and this is guaranteed in the code

Calendar* U_EXPORT2
Calendar::createInstance(TimeZone* zone, const Locale& aLocale, UErrorCode& success)
{
...
    // Now, reset calendar to default state:
    c->adoptTimeZone(zonePtr.orphan()); //  Set the correct time zone
    c->setTimeInMillis(getNow(), success); // let the new calendar have the current time.
    return c;
}

c->setTimeInMillis(getNow(), success); // let the new calendar have the current time.

And there are no need for all the setTimeInMillis(getNow(), success); inside each constructor

  1. Remove overloading of operator= in Calendar since these implementation currently are the same as compiler generated assignment operator
  2. Simplified the GregorianCalendar constructor by chaining the calls
  3. add "static const int32_t kDefaultCutoverYear = 1582;" inside GregorianCalendar to make it clear

Checklist

  • Required: Issue filed: ICU-22991
  • Required: The PR title must be prefixed with a JIRA Issue number. Example: "ICU-1234 Fix xyz"
  • Required: The PR description must include the link to the Jira Issue, for example by completing the URL in the first checklist item
  • Required: Each commit message must be prefixed with a JIRA Issue number. Example: "ICU-1234 Fix xyz"
  • Issue accepted (done by Technical Committee after discussion)
  • Tests included, if applicable
  • API docs and/or User Guide docs changed or added, if applicable

@FrankYFTang FrankYFTang merged commit e515c84 into unicode-org:main Dec 23, 2024
94 checks passed
@FrankYFTang FrankYFTang deleted the cleanUpCalendar branch December 23, 2024 20:52
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

Successfully merging this pull request may close these issues.

2 participants