Turn lift date and time strings into struct Time
authorPhilipp Zabel <philipp.zabel@gmail.com>
Mon, 3 May 2010 18:15:59 +0000 (20:15 +0200)
committerPhilipp Zabel <philipp.zabel@gmail.com>
Mon, 3 May 2010 18:48:33 +0000 (20:48 +0200)
src/adac-mitfahrclub.vala
src/beifahrer-cli.vala
src/lift-detail-window.vala
src/lift-list-window.vala

index 10b2221..516c9af 100644 (file)
@@ -49,8 +49,7 @@ public enum LiftFlags {
 public class Lift : Object {
        public string city_from;
        public string city_to;
-       public string date;
-       public string time;
+       public Time time;
        public int places;
        public string price;
        public LiftFlags flags;
@@ -65,6 +64,10 @@ public class Lift : Object {
        public string email;
        public string description;
        public string modified;
+
+       public Lift () {
+               time.hour = -1;
+       }
 }
 
 public class CallbackMessage : Soup.Message {
@@ -329,10 +332,10 @@ public class AdacMitfahrclub {
                                                                        lift.city_to = n3->content;
                                                                        break;
                                                                case 2:
-                                                                       lift.date = n3->content;
+                                                                       parse_date (n3->content, out lift.time);
                                                                        break;
                                                                case 3:
-                                                                       lift.time = n3->content;
+                                                                       parse_time (n3->content.strip (), out lift.time);
                                                                        break;
                                                                case 4:
                                                                        lift.places = n3->content.to_int ();
@@ -439,9 +442,7 @@ public class AdacMitfahrclub {
 
                                var text1 = n2->children->content.strip ();
 
-                               if (text == "Datum")
-                                       lift.date = text1;
-                               else if (text == "Freie Pl\xc3\xa4tze")
+                               if (text == "Freie Pl\xc3\xa4tze")
                                        lift.places = text1.to_int ();
                                else if (text == "Name")
                                        lift.name = text1;
@@ -490,9 +491,9 @@ public class AdacMitfahrclub {
                                else if (text1 == "nach")
                                        lift.city_to = text2;
                                else if (text1 == "Datum")
-                                       lift.date = text2;
+                                       parse_date (text2, out lift.time);
                                else if (text1 == "Uhrzeit")
-                                       lift.time = text2;
+                                       parse_time (text2, out lift.time);
                                else if (text1 == "Raucher")
                                        print ("Raucher: %s\n", text2);
                                else if (text1 == "Fahrpreis")
@@ -540,4 +541,18 @@ public class AdacMitfahrclub {
        Xml.Node* search_tag_by_class (Xml.Node* node, string tag, string @class) requires (node != null) {
                return search_tag_by_property (node, tag, "class", @class);
        }
+
+       void parse_date (string date, out Time time) {
+               int year;
+               if (date.length == 11)
+                       date = date.offset (3);
+               if (date.length != 8)
+                       return;
+               var res = date.scanf ("%02d.%02d.%02d", out time.day, out time.month, out year);
+               time.year = year + 2000;
+       }
+
+       void parse_time (string time, out Time result) {
+               var res = time.scanf ("%d.%02d Uhr", out result.hour, out result.minute);
+       }
 }
index 9b5b1ef..74ad7c0 100644 (file)
@@ -25,7 +25,10 @@ async void get_lifts (string city_from, string city_to, Date date) {
 
        var lift_list = yield adac.get_lift_list (city_from, city_to, date);
        foreach (Lift lift in lift_list) {
-               print ("%s\t%s\t%s\t%s\t%d\t%s\t", lift.city_from, lift.city_to, lift.date, lift.time, lift.places, lift.price);
+               string datetime = "%02d.%02d.%02d".printf (lift.time.day, lift.time.month, lift.time.year);
+               if (lift.time.hour >= 0)
+                       datetime += ", %d:%02d".printf (lift.time.hour, lift.time.minute);
+               print ("%s\t%s\t%s\t%d\t%s\t", lift.city_from, lift.city_to, datetime, lift.places, lift.price);
                if (LiftFlags.SMOKER in lift.flags)
                        print ("smoker ");
                else if (LiftFlags.NON_SMOKER in lift.flags)
@@ -46,7 +49,10 @@ async void get_details (string href) {
        lift.href = href;
        yield adac.update_lift_details (lift);
 
-       print ("%s\t%s\t%s\t%s\t%d\t%s\t", lift.city_from, lift.city_to, lift.date, lift.time, lift.places, lift.price);
+       string datetime = "%02d.%02d.%02d".printf (lift.time.day, lift.time.month, lift.time.year);
+       if (lift.time.hour >= 0)
+               datetime += ", %d:%02d".printf (lift.time.hour, lift.time.minute);
+       print ("%s\t%s\t%s\t%d\t%s\t", lift.city_from, lift.city_to, datetime, lift.places, lift.price);
        if (LiftFlags.SMOKER in lift.flags)
                print ("smoker ");
        else if (LiftFlags.NON_SMOKER in lift.flags)
index de6b8c8..c354383 100644 (file)
@@ -134,7 +134,7 @@ public class LiftDetailWindow : StackableWindow {
                        button_route.value = "";
                }
 
-               button_calendar.value = "%s, %s".printf (lift.date, lift.time);
+               button_calendar.value = "%02d.%02d.%04d, %d:%02d".printf (lift.time.day, lift.time.month, lift.time.year, lift.time.hour, lift.time.minute);
 
                label_driver.set_text (_("Driver: ") + lift.name);
                if (lift.cell != null) {
index 3cacf10..f932a7b 100644 (file)
@@ -115,8 +115,11 @@ public class LiftListWindow : StackableWindow {
                                icon_name = "beifahrer_smoker";
                        else if (LiftFlags.NON_SMOKER in lift.flags)
                                icon_name = "beifahrer_non_smoker";
+                       string datetime = "%02d.%02d.%04d".printf (lift.time.day, lift.time.month, lift.time.year);
+                       if (lift.time.hour >= 0)
+                               datetime += ", %d:%02d".printf (lift.time.hour, lift.time.minute);
                        store.insert_with_values (out iter, -1, 0, lift.city_from + " - " + lift.city_to,
-                                                               1, (lift.time != null) ? (lift.date + ", " + lift.time) : lift.date,
+                                                               1, datetime,
                                                                2, _("%d pl.").printf (lift.places),
                                                                3, lift.price,
                                                                4, icon_name,