golang-module / carbon

A simple, semantic and developer-friendly golang package for time

Home Page:https://pkg.go.dev/github.com/golang-module/carbon/v2

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

tanqiangyes opened this issue · comments

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.

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

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

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.

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.

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

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

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

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

image
Nanoseconds exist in your concrete realization.

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

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

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

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?

Optimized in v2.3.0
image