rayes0 / dotfiles

dotfiles for bash, neovim, tmux, widgets, and more
74 stars 0 forks source link

Calendar initializing with incorrect date #5

Closed GideonWolfe closed 3 years ago

GideonWolfe commented 3 years ago

Again, sorry about the issue spam but I can't tell if this is from something I did or not.

Right after I run eww-start and open the calendar, I see

image

On the top you can see the correct date as displayed by polybar. Even the eww calendar is correctly highlighting the current date.

However somehow year_cal. weekday_cal, and the other variables are set incorrectly.

eww state | grep cal

day_num_cal: 3
month_cal: Apr
weekday_cal: Sat
year_cal: 2021

I haven't really altered the calendar.sh script at all aside from parsing my appointments from khal instead of calcurse.

#!/bin/bash
# eww ouputs date format as DAY.MONTH.YEAR with no leading zeros

# Need these to be computed lightning fast
# Neither calcurse nor date need leading zeros, so we don't have to worry about those
day="${1%%.*}"
month="${1#*.}"
month="${month%.*}"
month=$((month+1)) # for some reason eww gives the month as a zero-based integer
year="${1##*.}"

IFS=$'\n'
# appointments=( $(calcurse --input-datefmt 4 --format-apt "%m\n" --format-recur-apt "%m\n" -d "${year}-${month}-${day}" | tail -n +2) )
# appointment_times=( $(calcurse --input-datefmt 4 --format-apt "%S - %E\n" --format-recur-apt "%S - %E\n" -d ${year}-${month}-${day} | tail -n +2) )
appointments=( $(khal list "${month}/${day}/${year}" 1d --day-format="" --format '{title}') )
appointment_times=( $(khal list "${month}/${day}/${year}" 1d --day-format="" --format '{start-time} - {end-time}') )

# Sort these by approximate expected duration and run in parallel to gain execution time
eww update appointment_times="$(printf '%s\n' "${appointment_times[@]}")" &
eww update appointment_names="$(printf '%s\n' "${appointments[@]}")" &
eww update next_appointment="$(printf '%s\n' " ${appointments[0]} ")" &
eww update month_cal="$(date --date="${year}-${month}-${day}" +%b)" &
eww update weekday_cal="$(date --date="${year}-${month}-${day}" +%a)" &
eww update day_num_cal="$day" &
eww update year_cal="$year" &

Thanks

rayes0 commented 3 years ago

Removing this line:

month=$((month+1)) # for some reason eww gives the month as a zero-based integer

will solve the problem. This was to accommodate for older versions of eww where the month were numbered starting from 0. They have since changed this and now number months correctly starting from 1. I have not pushed the commit to change this yet though, glad you caught it!

GideonWolfe commented 3 years ago

Hmm. image It still seems to be off. The day is correct, but one month behind.

I added the line back in, restarted eww, and it seems to be working?! I cloned eww like three days ago, is that still on the old version?

just checked, i'm up to date with master.

rayes0 commented 3 years ago

Oh, I thought they had it fixed, but seems it's still like that. Yeah, keeping the line in should fix it then.