From 0f0521166eb6f8653ed37fd1e6e695fc17200db8 Mon Sep 17 00:00:00 2001 From: San Jacobs Date: Sat, 1 Nov 2025 01:05:17 +0100 Subject: Small fixes --- time.odin | 104 ++++++++++++++++++++++++++++++++------------------------------ 1 file changed, 54 insertions(+), 50 deletions(-) (limited to 'time.odin') diff --git a/time.odin b/time.odin index f98f0ff..2cdbe72 100644 --- a/time.odin +++ b/time.odin @@ -394,57 +394,61 @@ importICS :: proc(path: string, verbose: bool = false) -> ([dynamic]Timeblock, b // BUG: This assumes that there will never be a line shorter than 10. // That means this will try reading out of bounds at some point. - - if line[0:10]=="DTSTART;TZ" { - // grab the timestamp from the end of the line, and set start to it - - ll := len(line) - if verbose do fmt.println("Found a DTSTART!") - if verbose do fmt.println("length of line:", ll) - if verbose do fmt.println(line) - date_start : int - - if verbose do fmt.printf("Time: %s:%s\n", line[ll-6:ll-4], line[ll-4:ll-2]) - - if verbose do fmt.printf("Hours: %s\n", line[ll-6:ll-4]) - c.start.hours = strconv.atoi(line[ll-6:ll-4]) - - if verbose do fmt.printf("Minutes: %s\n", line[ll-4:ll-2]) - c.start.minutes = strconv.atoi(line[ll-4:ll-2]) - - if verbose do fmt.printf("Day: %s\n", line[ll-9:ll-7]) - c.start.day = strconv.atoi(line[ll-9:ll-7]) - - if verbose do fmt.printf("Month: %s\n", line[ll-11:ll-9]) - c.start.month = strconv.atoi(line[ll-11:ll-9]) - - if verbose do fmt.printf("Year: %s\n", line[ll-15:ll-11]) - c.start.year = strconv.atoi(line[ll-15:ll-11]) + + if len(line)>=10 { + if line[0:10]=="DTSTART;TZ" { + // grab the timestamp from the end of the line, and set start to it + + ll := len(line) + if verbose do fmt.println("Found a DTSTART!") + if verbose do fmt.println("length of line:", ll) + if verbose do fmt.println(line) + date_start : int + + if verbose do fmt.printf("Time: %s:%s\n", line[ll-6:ll-4], line[ll-4:ll-2]) + + if verbose do fmt.printf("Hours: %s\n", line[ll-6:ll-4]) + c.start.hours, _ = strconv.parse_int(line[ll-6:ll-4]) + + if verbose do fmt.printf("Minutes: %s\n", line[ll-4:ll-2]) + c.start.minutes, _ = strconv.parse_int(line[ll-4:ll-2]) + + if verbose do fmt.printf("Day: %s\n", line[ll-9:ll-7]) + c.start.day, _ = strconv.parse_int(line[ll-9:ll-7]) + + if verbose do fmt.printf("Month: %s\n", line[ll-11:ll-9]) + c.start.month, _ = strconv.parse_int(line[ll-11:ll-9]) + + if verbose do fmt.printf("Year: %s\n", line[ll-15:ll-11]) + c.start.year, _ = strconv.parse_int(line[ll-15:ll-11]) + } } - if line[0:5]=="DTEND" { - // grab the timestamp from the end of the line, and set end to it - ll := len(line) - if verbose do fmt.println("Found a DTEND!") - if verbose do fmt.println(line) - - - if verbose do fmt.printf("Time: %s:%s\n", line[ll-6:ll-4], line[ll-4:ll-2]) - - if verbose do fmt.printf("Hours: %s\n", line[ll-6:ll-4]) - c.end.hours = strconv.atoi(line[ll-6:ll-4]) - - if verbose do fmt.printf("Minutes: %s\n", line[ll-4:ll-2]) - c.end.minutes = strconv.atoi(line[ll-4:ll-2]) - - if verbose do fmt.printf("Day: %s\n", line[ll-9:ll-7]) - c.end.day = strconv.atoi(line[ll-9:ll-7]) - - if verbose do fmt.printf("Month: %s\n", line[ll-11:ll-9]) - c.end.month = strconv.atoi(line[ll-11:ll-9]) - - if verbose do fmt.printf("Year: %s\n", line[ll-15:ll-11]) - c.end.year = strconv.atoi(line[ll-15:ll-11]) - + if len(line)>=5 { + if line[0:5]=="DTEND" { + // grab the timestamp from the end of the line, and set end to it + ll := len(line) + if verbose do fmt.println("Found a DTEND!") + if verbose do fmt.println(line) + + + if verbose do fmt.printf("Time: %s:%s\n", line[ll-6:ll-4], line[ll-4:ll-2]) + + if verbose do fmt.printf("Hours: %s\n", line[ll-6:ll-4]) + c.end.hours, _ = strconv.parse_int(line[ll-6:ll-4]) + + if verbose do fmt.printf("Minutes: %s\n", line[ll-4:ll-2]) + c.end.minutes, _ = strconv.parse_int(line[ll-4:ll-2]) + + if verbose do fmt.printf("Day: %s\n", line[ll-9:ll-7]) + c.end.day, _ = strconv.parse_int(line[ll-9:ll-7]) + + if verbose do fmt.printf("Month: %s\n", line[ll-11:ll-9]) + c.end.month, _ = strconv.parse_int(line[ll-11:ll-9]) + + if verbose do fmt.printf("Year: %s\n", line[ll-15:ll-11]) + c.end.year, _ = strconv.parse_int(line[ll-15:ll-11]) + + } } if line[0:min(8, len(line))]=="SUMMARY:" { if verbose do fmt.println("Found a SUMMARY!") -- cgit v1.2.1