<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -37,10 +37,8 @@
 #   [x] timezone stuff
 #   [x] recurrence
 #   [x] use optparser
+#   [x] check for stuff removed on the g side
 #   [ ] all day events (OK, but 1 day late)
-#   [ ] check for stuff removed on the g side
-#       (well, by deleting the itog.yaml and flushing the calendar the user
-#       can trigger a 'reload all'... well...)
 #   [ ] package in gem:bin/ or something like that
 #
 
@@ -111,12 +109,16 @@ raise &quot;no calendar named '#{TARGET_GCAL}'&quot; unless GCAL
 #
 # :(  what if there's a shitload of them ?
 
-#GCAL_EVENTS = GCAL.events.inject({}) { |h, e| h[
-GCAL_EVENTS = GCAL.events
+query = {} # TODO : restrict to a given (opt) timeframe
 
-puts &quot; .  found #{GCAL_EVENTS.size} events in the '#{TARGET_GCAL}' gcal&quot;
+GCAL_EVENTS = GCAL.events(query).inject({}) { |h, e|
+  h[e.entry.id.split('/').last] = e; h
+} # is the event id unique ??
 
+puts &quot; .  found #{GCAL_EVENTS.size} events in the '#{TARGET_GCAL}' gcal&quot;
 
+# ical datetime to UTC
+#
 def adjust_dt (dt)
   return nil unless dt
   dt - DateTime.now.offset
@@ -154,14 +156,21 @@ def gpost! (ical_event)
   end
 end
 
+# Returns the entry corresponding to the given gcal URI
+#
+def lookup_entry (gcal_uri)
+  GCAL_EVENTS[gcal_uri.split('/').last]
+end
 
-# Deletes gcal event with given uri.
+# Deletes gcal event with given entry.
 # Returns false if deletion failed
 #
 def gdelete! (gcal_uri)
 
+  gcal_entry = gcal_uri.is_a?(String) ? lookup_entry(gcal_uri) : gcal_uri
+
   begin
-    GCAL.delete!(gcal_uri)
+    GCAL.delete!(gcal_entry)
     true
   rescue Exception =&gt; e
     puts &quot; !  #{e}&quot;
@@ -208,7 +217,7 @@ icses.each do |ics|
 
   mtime, cal = File.open(events_path + ics) { |f|
 
-    [ f.mtime.iso8601, Icalendar.parse(f, true) ]
+    [ f.mtime.gmtime.iso8601, Icalendar.parse(f, true) ]
       # 'true' : assuming one cal per .ics file
   }
 
@@ -220,22 +229,25 @@ icses.each do |ics|
 
     cached = cache[e.uid]
 
+    on_gcal = cached ? lookup_entry(cached[1]) : false
+    gcal_ok = if on_gcal
+      pt = on_gcal.entry.published.iso8601
+      mt = on_gcal.entry.edited.iso8601
+      (pt == mt)
+    else
+      false
+    end
+
     seen &lt;&lt; e.uid
 
-    if cached and cached[0] == mtime
-      #
-      # already posted to g, but has it changed there meanwhile ?
-      # or vanished ?
-      #
-      # TODO : check if in GCAL_EVENTS or if gcal_event.mtime matches...
-      #
+    if cached and cached[0] == mtime and gcal_ok
       puts &quot; .  #{summary}&quot;
       next
     end
 
-    if cached
+    if cached and on_gcal
       puts &quot; -  #{e.summary}&quot;
-      unless gdelete!(cached[1])
+      unless gdelete!(on_gcal)
         puts  ' !  failed to delete in gcal... skipping for now'
         next
       end
@@ -264,7 +276,7 @@ if seen.sort != cache.keys.sort
   not_seen.each do |uid|
     info = cache[uid]
     puts &quot; -  #{info[2]}&quot;
-    #gcal.delete!(info[1])
+    gdelete!(info[1])
     cache.delete(uid)
   end
 end</diff>
      <filename>tools/itog.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>854e7d4906da443f66a852e2ec6a8739ab6735ef</id>
    </parent>
  </parents>
  <author>
    <name>John Mettraux</name>
    <email>jmettraux@gmail.com</email>
  </author>
  <url>http://github.com/jmettraux/rufus-google/commit/ec98917d32b07fb03eeeeb7f26b7a06c33b63769</url>
  <id>ec98917d32b07fb03eeeeb7f26b7a06c33b63769</id>
  <committed-date>2008-12-01T01:00:06-08:00</committed-date>
  <authored-date>2008-12-01T01:00:06-08:00</authored-date>
  <message>improved 'push to gcal'</message>
  <tree>e7e66dc89f3437658ba3de86fd51b3ce7f599a7f</tree>
  <committer>
    <name>John Mettraux</name>
    <email>jmettraux@gmail.com</email>
  </committer>
</commit>
