aboutsummaryrefslogtreecommitdiff
path: root/src/time.odin
diff options
context:
space:
mode:
Diffstat (limited to 'src/time.odin')
-rw-r--r--src/time.odin67
1 files changed, 57 insertions, 10 deletions
diff --git a/src/time.odin b/src/time.odin
index f355e98..853aa95 100644
--- a/src/time.odin
+++ b/src/time.odin
@@ -370,9 +370,14 @@ 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)
@@ -380,27 +385,69 @@ importICS :: proc(path: string) -> ([dynamic]Timeblock, bool) {
}
for line in strings.split_lines_iterator(&content) {
- if line[0:7]=="DTSTART" {
- fmt.println(len(line))
- date_start : int
-
- for i := len(line)-1 ; i>0 ; i-=1 {
- fmt.println(rune(line[i]))
- }
-
+ 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])
+
}
- if line=="END:VEVENT" {
+ if line=="END:VEVENT" && (c.end.year != 0) && (c.start.year != 0) {
fmt.println(line)
- //append(output, _)
+ 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
}