aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSan Jacobs2023-09-08 23:22:24 +0200
committerSan Jacobs2023-09-08 23:22:24 +0200
commitb90fbef0a8e7acf3d4a485ca83126afc8a745828 (patch)
treee7ca695819ca45e74720409097ee3c0ede6cdfec /src
parent2a9550709c007d530aae506a5f95bd703f6f7803 (diff)
downloadsatscalc-b90fbef0a8e7acf3d4a485ca83126afc8a745828.tar.gz
satscalc-b90fbef0a8e7acf3d4a485ca83126afc8a745828.tar.bz2
satscalc-b90fbef0a8e7acf3d4a485ca83126afc8a745828.zip
ICS import is functional!
Diffstat (limited to 'src')
-rw-r--r--src/main.odin27
-rw-r--r--src/time.odin67
2 files changed, 77 insertions, 17 deletions
diff --git a/src/main.odin b/src/main.odin
index 729715b..7884f28 100644
--- a/src/main.odin
+++ b/src/main.odin
@@ -13,12 +13,24 @@ main :: proc() {
// for cache reasons, and to simplify the process of
// adding new Workdays to the array.
- _, _ = importICS("res/test.ics")
+ workdays : [dynamic]Workday
+ //resize(&workdays, 3)
+
+ { // No need to keep this array in memory forever
+ c, _ := importICS("res/test.ics")
+
+ for thing, i in c {
+ fmt.println("\n\nAdding workday nr", i, "\n", toString(thing), "\n")
+ append(&workdays, new_workday({00, 00, 1, 1, 1850},
+ thing.start,
+ thing.end,
+ thing.end))
+ }
+ }
- workdays: [dynamic]^Workday
- resize(&workdays, 3)
+ //if true do return
- workday0: = new_workday({10, 22, 3, 5, 2023},
+ /*workday0: = new_workday({10, 22, 3, 5, 2023},
{00, 08, 4, 5, 2023},
{00, 22, 4, 5, 2023},
{30, 21, 4, 5, 2023})
@@ -35,8 +47,9 @@ main :: proc() {
{15, 17, 6, 5, 2023},
{00, 17, 6, 5, 2023})
workdays[2] = &workday2
+ */
- slice.sort_by(workdays[:], lessWorkdayPtr)
+ slice.sort_by(workdays[:], lessWorkday)
//call_text: cstring = "00:00"
call_text: = make([]byte, 6)
@@ -47,7 +60,7 @@ main :: proc() {
defer delete(wrap_text)
wrap_text[len(wrap_text)-1] = 0
- date_text: = make([]byte, len(toString(workday0.call))+1 )
+ date_text: = make([]byte, len(toString(workdays[0].call))+1 )
defer delete(date_text)
wrap_text[len(wrap_text)-1] = 0
@@ -83,7 +96,7 @@ main :: proc() {
// Setting up the timelines
- for day in workdays {
+ for day in &workdays {
beginning: Moment = {0, 0, day.call.day, day.call.month, day.call.year}
fmt.println("\nNew day!")
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
}