@@ -14,12 +14,12 @@ public class TimelineItem {
1414 public Place place ;
1515 public Activity activity ;
1616
17- public TimelineItem ( Place place ) {
17+ public TimelineItem ( Place place ) {
1818 type = TimelineItemType . place ;
1919 this . place = place ;
2020 }
2121
22- public TimelineItem ( Activity activity ) {
22+ public TimelineItem ( Activity activity ) {
2323 type = TimelineItemType . activity ;
2424 this . activity = activity ;
2525 }
@@ -31,6 +31,7 @@ public override string ToString() {
3131 return place . ToString ( ) ;
3232 }
3333
34+ //Time
3435 public DateTime ReturnDate ( ) {
3536 DateTime tempDate = new DateTime ( ) ;
3637 if ( type == TimelineItemType . activity )
@@ -39,6 +40,36 @@ public DateTime ReturnDate() {
3940 tempDate = place . startTime . Value ;
4041 return new DateTime ( tempDate . Year , tempDate . Month , tempDate . Day , 12 , 0 , 0 , tempDate . Kind ) ;
4142 }
43+
44+ public DateTime EndTime {
45+ get {
46+ if ( type == TimelineItemType . activity )
47+ return activity . endTime ;
48+ else
49+ return place . endTime . Value ;
50+ }
51+ set {
52+ if ( type == TimelineItemType . activity )
53+ activity . endTime = value ;
54+ else
55+ place . endTime = value ;
56+ }
57+ }
58+
59+ public DateTime StartTime {
60+ get {
61+ if ( type == TimelineItemType . activity )
62+ return activity . startTime ;
63+ else
64+ return place . startTime . Value ;
65+ }
66+ set {
67+ if ( type == TimelineItemType . activity )
68+ activity . startTime = value ;
69+ else
70+ place . startTime = value ;
71+ }
72+ }
4273 }
4374
4475 public class Coordinates {
@@ -203,10 +234,13 @@ public class XmlReader {
203234 List < XmlTimeline . Activity > [ ] activitySummary = new List < XmlTimeline . Activity > [ 10 ] ;
204235 public DateTime date ;
205236 public ActivitySummary [ ] summary = new ActivitySummary [ 10 ] ;
206- string originalName ;
237+ public string originalName ;
207238
208239 // Activity and places loading
209240 public XmlReader ( string path ) {
241+ Console . ForegroundColor = ConsoleColor . DarkGray ;
242+ Console . WriteLine ( ) ;
243+ Console . WriteLine ( "Opening file: " + path ) ;
210244 originalName = path . Replace ( ".gpx" , "" ) ;
211245 LoadFile ( path ) ;
212246 }
@@ -215,9 +249,9 @@ public XmlReader(List<XmlTimeline.TimelineItem> timelineItems) {
215249 activitySummary [ i ] = new List < XmlTimeline . Activity > ( ) ;
216250 }
217251 this . timelineItems = timelineItems ;
218- Console . WriteLine ( "Creating with items: " + timelineItems . Count ) ;
219- SetStartEnd ( ) ;
252+ //SetStartEnd();
220253 SetSummary ( ) ;
254+ SetXmlDate ( ) ;
221255 }
222256
223257 public void LoadFile ( string path ) {
@@ -244,6 +278,7 @@ public void LoadFile(string path) {
244278 sr . Close ( ) ;
245279 SetStartEnd ( ) ;
246280 SetSummary ( ) ;
281+ SetXmlDate ( ) ;
247282
248283 //Display();
249284 }
@@ -316,24 +351,35 @@ void AddTimeToPreviousPlace(XmlTimeline.Activity activity) {
316351
317352 // End calculations
318353 void SetStartEnd ( ) {
319- if ( timelineItems . First ( ) . type == XmlTimeline . TimelineItemType . place ) {
354+ if ( timelineItems . First ( ) . type == XmlTimeline . TimelineItemType . place && ! timelineItems . First ( ) . place . startTime . HasValue ) {
320355 DateTime time = timelineItems . First ( ) . place . endTime . Value ;
321356 DateTime newTime = new DateTime ( time . Year , time . Month , time . Day , 0 , 0 , 0 , time . Kind ) ;
322357 timelineItems . First ( ) . place . startTime = newTime ;
323358 }
324359
325- if ( timelineItems . Last ( ) . type == XmlTimeline . TimelineItemType . place ) {
360+ if ( timelineItems . Last ( ) . type == XmlTimeline . TimelineItemType . place && ! timelineItems . Last ( ) . place . endTime . HasValue ) {
326361 DateTime time = timelineItems . Last ( ) . place . startTime . Value ;
327362 DateTime newTime = new DateTime ( time . Year , time . Month , time . Day , 23 , 59 , 59 , time . Kind ) ;
328363 timelineItems . Last ( ) . place . endTime = newTime ;
329364 }
330-
365+ }
366+ void SetXmlDate ( ) {
331367 DateTime tempDate = new DateTime ( ) ;
332- if ( timelineItems . First ( ) . type == XmlTimeline . TimelineItemType . activity ) {
333- tempDate = timelineItems . First ( ) . activity . startTime ;
334- } else
335- tempDate = timelineItems . First ( ) . place . startTime . Value ;
336- date = new DateTime ( tempDate . Year , tempDate . Month , tempDate . Day ) ;
368+
369+ if ( timelineItems . Count > 1 ) {
370+ tempDate = timelineItems . First ( ) . EndTime ;
371+ } else {
372+ DateTime tempEndTime = timelineItems [ 0 ] . EndTime ;
373+ if ( tempEndTime . Day - timelineItems [ 0 ] . StartTime . Day == 2 ) {
374+ tempDate = timelineItems . First ( ) . StartTime ;
375+ tempDate . AddDays ( 1 ) ;
376+ } else if ( tempEndTime . Hour == 23 && tempEndTime . Minute == 59 && tempEndTime . Second == 59 )
377+ tempDate = tempEndTime ;
378+ else
379+ tempDate = timelineItems [ 0 ] . StartTime ;
380+ }
381+
382+ date = new DateTime ( tempDate . Year , tempDate . Month , tempDate . Day , 12 , 0 , 0 , tempDate . Kind ) ;
337383 }
338384 void SetSummary ( ) {
339385 foreach ( var item in timelineItems ) {
@@ -376,6 +422,7 @@ public static List<XmlReader> Split(XmlReader xml) {
376422 DateTime ? currentDate = null ;
377423 List < XmlReader > output = new List < XmlReader > ( ) ;
378424 List < XmlTimeline . TimelineItem > tempList = new List < XmlTimeline . TimelineItem > ( ) ;
425+ XmlTimeline . TimelineItem lastItem = timelineItems [ 0 ] ;
379426
380427 foreach ( var item in timelineItems ) {
381428 if ( ! currentDate . HasValue ) {
@@ -384,12 +431,15 @@ public static List<XmlReader> Split(XmlReader xml) {
384431
385432 if ( currentDate == item . ReturnDate ( ) ) {
386433 tempList . Add ( item ) ;
434+ lastItem = item ;
387435 } else {
388436 XmlReader tempXml = new XmlReader ( tempList . ToArray ( ) . ToList ( ) ) ; // stupid workaround to clone
389437 output . Add ( tempXml ) ;
390438 tempList . Clear ( ) ;
391439 currentDate = item . ReturnDate ( ) ;
440+ tempList . Add ( lastItem ) ;
392441 tempList . Add ( item ) ;
442+ lastItem = item ;
393443 }
394444 }
395445 output . Add ( new XmlReader ( tempList . ToArray ( ) . ToList ( ) ) ) ;
0 commit comments