Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2.29 Not present #58

Open
herculewyy opened this issue Feb 10, 2023 · 3 comments
Open

2.29 Not present #58

herculewyy opened this issue Feb 10, 2023 · 3 comments

Comments

@herculewyy
Copy link

    var dd = "2023-01-30 12:45:23"

loc, _ := time.LoadLocation("Local")

dt, _ := time.ParseInLocation("2006-01-02 15:04:05", dd, loc)

r, _ = rrule.NewRRule(rrule.ROption{
	Freq: rrule.MONTHLY,
	//Bymonthday: []int{},
	//	Bymonth:    []int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}, // 取哪一月的数据
	Interval: 1,
	Until:    time.Now().AddDate(0, 5, 0),
	Dtstart:  dt,
})

//set.ExDate(time.Now())
for _, t2 := range r.All() {
	fmt.Println(t2.Format("2006-01-02 15:04:05"))
}

result:
2023-01-30 12:45:23
2023-03-30 12:45:23
2023-04-30 12:45:23
2023-05-30 12:45:23
2023-06-30 12:45:23

2023-02-28 12:45:23 How to achieve?

thank you

@herculewyy
Copy link
Author

Starting from 1.31, the frequency is every month, then I want to get the last day of February (2.28 or 2.29)

@while-loop
Copy link

while-loop commented Feb 18, 2023

Feb 29, 2023 is not a real date

Maybe something along the lines of the 30th of every month or last day.

Probably done with a ruleset

@KaiChen1008
Copy link

the following code works for me

func printTime(ts []time.Time) {
	for _, t := range ts {
		fmt.Println(t)
	}
}

func main() {
	loc, _ := time.LoadLocation("Local")
	curr := time.Date(2024, 1, 28, 12, 45, 23, 0, loc)
	r, _ := rrule.NewRRule(rrule.ROption{
		Freq:       rrule.MONTHLY,
		Interval:   1,
		Bymonthday: []int{-1},
		Dtstart:    curr,
		Until:      curr.AddDate(0, 5, 0),
	})

	printTime(r.All())
}

output:

2024-01-31 12:45:23 +0800 CST
2024-02-29 12:45:23 +0800 CST
2024-03-31 12:45:23 +0800 CST
2024-04-30 12:45:23 +0800 CST
2024-05-31 12:45:23 +0800 CST

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants