dromara / carbon

A simple, semantic and developer-friendly golang package for time
https://pkg.go.dev/github.com/golang-module/carbon/v2
MIT License
4.77k stars 238 forks source link

Rename the func such as `carbon.CreateFromDate()`. #205

Closed tanqiangyes closed 10 months ago

tanqiangyes commented 10 months ago

Feature Request

Is your feature request related to a problem? Please describe: When I use carbon.CreateFromDate(2023,1,1), I think I will get the time 2023-01-01 00:00:00, but actually I get the time 2023-01-01 Current Hour: Current Minutes: Current Seconds Current Nanoseconds. I think this naming "CreateFromDate" is confusing and we should change it to something that describes its function more precisely, like " CreateFromDateUseCurrentHMS".

Describe the feature you'd like: Rename the func such as carbon.CreateFromDate().

Describe alternatives you've considered: Yes, we can use carbon.CreateFromDateTimeNano,but for a new user, CreateFromDate is still disorienting, which will cause unexpected bugs in their work

Teachability, Documentation, Adoption, Migration Strategy: With this renaming, users will know exactly what time they are using, and will not have a series of bugs caused by the use of this package, which can be implemented in a new version without affecting the old version of the code.

gouguoyin commented 10 months ago

Thank you for your feedback, I will seriously consider it.

tanqiangyes commented 10 months ago

If you need help, I'd be happy to provide it.

tanqiangyes commented 10 months ago

If you don't want to change the name, then perhaps the notes should be written more clearly? Because as it stands now, the notes don't describe what the functions do very clearly.

gouguoyin commented 10 months ago

I also hesitated when I first named it, CreateFromDate is to be consistent with CreateFromTime, in CreateFromTime, the year, month, and day are taken from current time, so, all omitted values are taken to the current time.

gouguoyin commented 10 months ago

Yesterday and Tomorrow have the same logic,hours, minutes and seconds are taken from the current time.

gouguoyin commented 10 months ago

2023-01-01 Current Hour: Current Minutes: Current Seconds Current Nanoseconds? No Current Nanoseconds

image
gouguoyin commented 10 months ago

Currently can use the following methods carbon.CreateFromDate(2023,1,1).StartOfDay() // 2023-01-01 00:00:00

tanqiangyes commented 10 months ago

I know that I can also use carbon.CreateFromDateTimeNano. But the confusing nature of function names is still there.

tanqiangyes commented 10 months ago

image Nanoseconds exist in your concrete realization.

2023-01-01 Current Hour: Current Minutes: Current Seconds Current Nanoseconds? No Current Nanoseconds image

gouguoyin commented 10 months ago

What should be the year, month and day in CreateFromTime? 0000-00-00 or currentYear-currentMonth-currentDay

tanqiangyes commented 10 months ago

What should be the year, month and day in CreateFromTime? 0000-00-00 or currentYear-currentMonth-currentDay

currentYear-currentMonth-currentDay maybe this, but nobody can kown this from func name or func comment

tanqiangyes commented 10 months ago

What should be the year, month and day in CreateFromTime? 0000-00-00 or currentYear-currentMonth-currentDay

As you said, is it 0000-00-00 or currentYear-currentMonth-currentDay which is unknown to the user?

gouguoyin commented 10 months ago

Optimized in v2.3.0

image