yaa110 / go-persian-calendar Goto Github PK
View Code? Open in Web Editor NEWThe implementation of Persian (Solar Hijri) Calendar in Go
Home Page: https://pkg.go.dev/github.com/yaa110/go-persian-calendar
License: MIT License
The implementation of Persian (Solar Hijri) Calendar in Go
Home Page: https://pkg.go.dev/github.com/yaa110/go-persian-calendar
License: MIT License
الان که همه ی سیستم ها به اینترنت متصل هستند پیشنهاد میکنم ارتباط با ای پی آي های تقویم رو هم در این سورس خوب پیاده سازی کنید
خودم از این سرویس زیاد استفاده میکنم
The main time package when timezone is UTC formats the date in RFC3339 like this:
2019-10-10T10:20:33Z
and for example for Tehran timezone formats like this:
2019-10-10T10:20:33+03:30
But your package for UTC acts as other timezones and formats as
1398-08-15T10:20:22+00:00
I think for consistency with main package you should format same as main time package
hey
first i wanna thank for your great repo.
second i have a question
is it possible to use ptime as type for sql database ?
i'm using gorm to connect database
type User struct {
gorm.Model
DeletedAt gorm.DeletedAt `gorm:"uniqueIndex:national_id_deleted_at_idx;uniqueIndex:phone_number_deleted_at_idx"`
FirstName string `gorm:"type:varchar(50);index;not null;"`
LastName string `gorm:"type:varchar(50);index;not null;"`
NationalID string `gorm:"type:varchar(10);index;not null;uniqueIndex:national_id_deleted_at_idx"`
PhoneNumber uint `gorm:"type:BIGINT(10)index;not null;uniqueIndex:phone_number_deleted_at_idx"`
BirthDate ptime.Time `gorm:"index;not null;"`
Gender Gender `gorm:"not null;default:'active'"`
Status Status `gorm:"not null;"`
Children []Child `gorm:"foreignKey:ParentID"`
}
when i try to do this and migrate database i get this error
[error] invalid field found for struct user.User's field BirthDate: define a valid foreign key for relations or implement the Valuer/Scanner interface
While appreciating the project, AddDate() not works correctly. As a sample, today is 2023-06-11 OR 1402/03/21
By using this sample (the dates of the days of the future years):
func main() {
pt := pTime.Now()
utility.UFileDelete("dates.txt")
for i := 0; i < 3650; i++ {
pd := pt.AddDate(0, 0, i)
utility.UFileAppend("dates.txt", strconv.Itoa(i)+" : "+pd.Format("yyyy/MM/dd E MMMMM D/RD w/rw")+"\n "+pd.Time().String()+"\n", false)
}
}
The output is (end of 1402):
Today + 286 -> 1402/12/28 2024-03-18
Today + 287 -> 1402/12/29 2024-03-19
Today + 288 -> 1402/12/29 2024-03-19
Today + 289 -> 1403/01/01 2024-03-20
Today + 290 -> 1403/01/01 2024-03-20
Today + 291 -> 1403/01/02 2024-03-21
But with updating the code as below by adding the days to standard time package:
func main() {
t := 10 * 365
now := time.Now()
utility.UFileDelete("dates.txt")
for i := 0; i < t; i++ {
p := now.AddDate(0, 0, i)
pt := pTime.Unix(p.Unix(), 0)
utility.UFileAppend("dates.txt", strconv.Itoa(i)+" : "+pt.Format("yyyy/MM/dd E MMMMM D/RD w/rw")+"\n "+pt.Time().Format(time.UnixDate)+"\n", false)
}
}
...
Today + 281 -> 1402/12/28 2024-03-18
Today + 282 -> 1402/12/29 2024-03-19
Today + 283 -> 1403/01/01 2024-03-20
Today + 284 -> 1403/01/02 2024-03-21
...
Today + 286 -> 1403/01/04 2024-03-23
Today + 287 -> 1403/01/05 2024-03-24
Today + 288 -> 1403/01/06 2024-03-25
Today + 289 -> 1403/01/07 2024-03-26
Today + 290 -> 1403/01/08 2024-03-27
...
The last day of 1403 is 1403-12-30 which is equal to the 2025-03-20. Try to convert 2025-03-20 to the Solar Hijri by passing a time.Time
object with 2025-03-20 value to the ptime.New
. The result will be 1404-01-01.
Hi there,
Thanks for sharing this amazing useful library.
How can I set my now date location to ptime.Iran()
:
pt := ptime.Now()
fmt.Println(pt.Location())
// output: Local
Can not calculate correctly Sub Days with AddDate function
example set the time to 1400-01-01
and use FirstWeekDay function to return
and you see return 1400-06-26 instead of 1400-06-27
I think the problem is with the time zone (+04:30 and +03:30)
Hi Navid
strconv.Itoa(t.nsec) string length rarely goes less than 6 and because of you trying to get a string with lenght 6 of it run time error happening, the problematic code is :
"{ms}", "." + strconv.Itoa(t.nsec)[:6],
and the error is :
panic: runtime error: slice bounds out of range [:6] with length 5
I fixed it in my fork by adding "0" charcter as needed to end of it's string.
Good Luck.
Thanks
The code will going to panic if the input value of ptime.New() is the zero value of time.Time
line 222: func (m Month) String() string {
return months[m-1]
}
cause when the time equals to "0001-01-01 00:01" the month array is going to have '-1' index and it is going to panic
Hey bro, may you contribute in this topic: https://discourse.gohugo.io/t/9403/
Note: Hugo is the fastest static site generator.
I think The FirstDayOfMonth()
method must be returns the first day of month and reset the time to 00:00:00, but the method only reset the date and keeps original time
when you add months or years you won't get an expected result in Jalali calendar.
Hi,
May you take a look at this topic: https://discuss.gohugo.io/t/are-native-non-gregorian-calendars-supported/2963/6 and share your info there.
Cheers
can't compare two different times
thanks!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.