diff options
Diffstat (limited to 'src/time.odin')
-rw-r--r-- | src/time.odin | 100 |
1 files changed, 100 insertions, 0 deletions
diff --git a/src/time.odin b/src/time.odin index 1f2ffbd..90dca49 100644 --- a/src/time.odin +++ b/src/time.odin @@ -2,6 +2,7 @@ package main import math "core:math" import "core:fmt" +import "core:os" import "core:strings" import "core:strconv" import "core:slice" @@ -366,6 +367,105 @@ upvalue :: proc(input_block: ^Timeblock, value: f32, reason: string) { } } +importICS :: proc(path: string) -> ([dynamic]Timeblock, bool) { + output: [dynamic]Timeblock + + c : Timeblock + + raw, ok := os.read_entire_file_from_filename(path) + content := string(raw) + + i := 1 + line_nr := 1 + + if !ok { + // TODO: Actually check the content to see if it is an ICS file. + fmt.eprintf("ERROR: No file found at: \"%v\"", path) + return output, false + } + + for line in strings.split_lines_iterator(&content) { + + // 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) + fmt.println("Found a DTSTART!") + fmt.println("length of line:", ll) + fmt.println(line) + date_start : int + + fmt.printf("Time: %s:%s\n", line[ll-6:ll-4], line[ll-4:ll-2]) + + fmt.printf("Hours: %s\n", line[ll-6:ll-4]) + c.start.hours = strconv.atoi(line[ll-6:ll-4]) + + fmt.printf("Minutes: %s\n", line[ll-4:ll-2]) + c.start.minutes = strconv.atoi(line[ll-4:ll-2]) + + fmt.printf("Day: %s\n", line[ll-9:ll-7]) + c.start.day = strconv.atoi(line[ll-9:ll-7]) + + fmt.printf("Month: %s\n", line[ll-11:ll-9]) + c.start.month = strconv.atoi(line[ll-11:ll-9]) + + fmt.printf("Year: %s\n", line[ll-15:ll-11]) + c.start.year = strconv.atoi(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) + fmt.println("Found a DTEND!") + fmt.println(line) + + + fmt.printf("Time: %s:%s\n", line[ll-6:ll-4], line[ll-4:ll-2]) + + fmt.printf("Hours: %s\n", line[ll-6:ll-4]) + c.end.hours = strconv.atoi(line[ll-6:ll-4]) + + fmt.printf("Minutes: %s\n", line[ll-4:ll-2]) + c.end.minutes = strconv.atoi(line[ll-4:ll-2]) + + fmt.printf("Day: %s\n", line[ll-9:ll-7]) + c.end.day = strconv.atoi(line[ll-9:ll-7]) + + fmt.printf("Month: %s\n", line[ll-11:ll-9]) + c.end.month = strconv.atoi(line[ll-11:ll-9]) + + fmt.printf("Year: %s\n", line[ll-15:ll-11]) + c.end.year = strconv.atoi(line[ll-15:ll-11]) + + } + + // TODO: This is checking if the years are 0 to make sure it hasn't read from + // from a line containing "DTSTART;VALUE" instead of "DTSTART;TZID" + // VALUE days are events that are set to last the entire day, + // as opposed to having a defined start and end point. + // + // This should eventually not be needed, because these days + // should also be imported based on the session's default-day settings + + if line=="END:VEVENT" && (c.end.year != 0) && (c.start.year != 0) { + fmt.println(line) + c.value = 1 + append(&output, c) + + blank_timeblock: Timeblock + c = blank_timeblock + + fmt.println("\n\n", i, line_nr, "\n\n") + i += 1 + } + line_nr += 1 + } + return output, true +} + + // // --- BASIC OPERATIONS --- // |