teambition / rrule-go

Go library for working with recurrence rules for calendar dates.
MIT License
310 stars 57 forks source link

Question: Timezone conversion #60

Closed pentiumoverdrive closed 1 year ago

pentiumoverdrive commented 1 year ago

So, this is just a question for this awesome go project :)

I'm having two systems talking to each other. One has a string saved such as (I really love this short format): FREQ=MONTHLY;DTSTART=20230222T092100;BYDAY=2WE

My other system pulls this string and converts it to specific dates. I will only use CET/CEST such as Europe/Stockholm.

When my receiving systems is interpreting this using rrule.StrToRRule, its always shows UTC. Fine, its probably some RFC thing. But Is there a clever way to have StrToRRule output the time in CET/CEST in this oneliner?

I couldn't find any examples on how to handle this i the docs (or in python dateutil). Right now I'm solving this by using time.LoadLocation in Go. Perhaps there is a better way?

Thanks!

zensh commented 1 year ago

You can use StrToROptionInLocation

    option, e := StrToROptionInLocation(rfcString, cest)
    if e != nil {
        return nil, e
    }
    return NewRRule(*option)