Coder Social home page Coder Social logo

Comments (3)

rickywiens avatar rickywiens commented on August 27, 2024 1

Hi, I spent some time today figuring this out. I have a fix working locally but it's not super great.

I think this has to do with func NewRRule and the way it pre-calculates the timeset on creation, and then when DtStart is set, it does not effect those pre-calculated values.

I have a unit test locally to reproduce the issue:

func TestSetTimezonesDtStartSticky(t *testing.T) {

	set := &Set{}
	rule, err := StrToRRule("FREQ=DAILY;COUNT=10;WKST=MO;BYHOUR=10;BYMINUTE=0;BYSECOND=0")

	if err != nil {
		panic(err)
	}

	set.RRule(rule)
	dt := time.Date(2019, 3, 6, 0, 0, 0, 0, time.UTC)
	set.DTStart(dt)

	// set.All() returns events in my local timezone instead of UTC
	for _, event := range set.All() {
		if event.Location().String() != time.UTC.String() {
			t.Errorf("Timezone set incorrectly on recurrence after DtStart set: [%s]", event.String())
		}
	}
}

But the way I fixed it was to recreate all the rrules and exrules when the DtStart is set:

// DTStart sets dtstart property for all rules in set
func (set *Set) DTStart(dtstart time.Time) {

	var newrruleset []*RRule
	var newexruleset []*RRule

	set.dtstart = dtstart

	for _, r := range set.rrule {
		r.dtstart = dtstart
		r.OrigOptions.Dtstart = dtstart
		nr, err := NewRRule(r.OrigOptions)
		if err != nil {
			return
		}
		newrruleset = append(newrruleset, nr)
	}

	for _, xr := range set.exrule {
		xr.dtstart = dtstart
		xr.OrigOptions.Dtstart = dtstart
		nxr, err := NewRRule(xr.OrigOptions)
		if err != nil {
			return
		}
		newexruleset = append(newexruleset, nxr)
	}

	set.rrule = newrruleset
	set.exrule = newexruleset
}

I don't particularly like that fix, so if you have some ideas I'd love to hear them :).

from rrule-go.

kristinn avatar kristinn commented on August 27, 2024

@rickywiens thank you for your quick response!

I will see what I can cook up and create a pull request if I think it's good enough. 😄

from rrule-go.

kristinn avatar kristinn commented on August 27, 2024

@rickywiens @damoye I've created a pull request with a fix.

Thank you.

from rrule-go.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.