volver a intentar arreglar fecha

This commit is contained in:
Cat /dev/Nulo 2023-07-28 11:08:59 -03:00
parent 0c94125978
commit a20d7f4545

15
main.go
View file

@ -41,10 +41,9 @@ func main() {
const timezoneOffset = -3 const timezoneOffset = -3
func cycle() { func cycle() {
now := time.Now() date := getDate()
lastWeek := now.Add(-time.Hour*24*time.Duration(now.Weekday()-time.Monday) + 8 - timezoneOffset) if time.Now().After(date) {
if now.Weekday() > time.Sunday && now.Add(time.Hour*timezoneOffset).After(lastWeek) { err := createIfNotExists(date.Format("semana 2006-01-02"))
err := createIfNotExists(lastWeek.Format("semana 2006-01-02"))
if err != nil { if err != nil {
log.Fatalln(err) log.Fatalln(err)
} }
@ -54,6 +53,14 @@ func cycle() {
cycle() cycle()
} }
func getDate() time.Time {
year, month, day := time.Now().Date()
currentZeroDay := time.Date(year, month, day, 0, 0, 0, 0, time.UTC)
now := time.Now()
zeroMonday := currentZeroDay.Add(time.Duration(-time.Hour * 24 * time.Duration(now.Weekday()-time.Monday)))
return zeroMonday.Add(time.Hour * (8 - timezoneOffset))
}
func createIfNotExists(topicName string) (err error) { func createIfNotExists(topicName string) (err error) {
streamId, err := bot.GetStreamId(stream) streamId, err := bot.GetStreamId(stream)
if err != nil { if err != nil {