Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add grace period to backdate smarts to account for LJ rounding dates …

…to full minutes, and for delays in callbacks and such.
  • Loading branch information...
commit 7270915be77406d8ee8f5e221bb642022e5b935a 1 parent 0491d70
@henrik authored
Showing with 16 additions and 7 deletions.
  1. +2 −1  README.markdown
  2. +14 −6 lj_tasks.rb
View
3  README.markdown
@@ -44,7 +44,8 @@ Properties for `create` and `update`:
:subject A string.
:body The entry contents. Passing nil or "" raises AccidentalDeleteError.
:tags An array of strings. Stored comma-separated, so no commas.
- :time A Time. LJ will use the time as-is, ignoring the time zone. Can be past or future. Defaults to now on create.
+ :time A Time. LJ will use the time as-is, ignoring the time zone. Can be past or future.
+ Defaults to now on create. Tries to be smart about backdating, see code comments.
:mood A string.
:music A string.
:location A string.
View
20 lj_tasks.rb
@@ -103,13 +103,21 @@ def delete(id)
protected
def assign_properties(entry, properties)
- # So LJ doesn't complain about entries out of time.
- now = properties.delete(:now) || Time.now
- if properties[:time] && properties[:time] != now
- properties[:backdated] = true
- end
- if properties[:time].is_a?(Time)
+ # So LJ doesn't complain about entries out of time. Entries are backdated
+ # if the :time is set to something other than the previous value or the
+ # current time (with a grace period of +/- one minute to account for delays
+ # and for LJ rounding to full minutes). If this logic doesn't work for
+ # you, explicitly pass a :backdated bool and that will be respected.
+ if properties[:time]
properties[:time] = LiveJournal.coerce_gmt(properties[:time])
+
+ unless properties.has_key?(:backdated)
+ now = LiveJournal.coerce_gmt(properties.delete(:now) || Time.now)
+ expected_time = entry.time || now
+ unless expected_time-60 < properties[:time] && properties[:time] <= expected_time+60 # grace period
+ properties[:backdated] = true
+ end
+ end
end
if properties.has_key?(:body)
Please sign in to comment.
Something went wrong with that request. Please try again.