 
   def extract_put_tags(post) do
      put_in(post, ["tags"], post["json_metadata"]["tags"])
+  end
+
+  def trim_trailing_ms(date) when is_bitstring(date) do
+     String.replace(date, ~r/\..+/, "")
   end
 
   def iterate(posts, state) do

     {:noreply, state}
  end

  def matches_tag_rule?(_, :whitelist,  []), do: true
  def matches_tag_rule?(_, :whitelist,  nil), do: true
  def matches_tag_rule?(_, :blacklist,  []), do: false
  def matches_tag_rule?(_, :blacklist,  nil), do: false
  def matches_tag_rule?(post, _, rules) when is_list(rules)  do
    tags_set = Enum.into(post["tags"], MapSet.new)
    filter_set = Enum.into(rules, MapSet.new)
    !MapSet.disjoint?(tags_set, filter_set)
  end

  def matches_created_rule?(_, nil), do: true
  def matches_created_rule?(_, %{only_after: "", only_before: ""}), do: true
  def matches_created_rule?(post, %{only_after: only_after, only_before: only_before}) do
    # offset is always zero, but required by ISO standard
    only_after = if only_after == "", do:  "1970-01-01", else: only_after
    only_before = if only_before == "", do:  "2038-01-01", else: only_before
    {:ok, only_after, 0} = DateTime.from_iso8601(only_after <> "T00:00:00Z")
    {:ok, only_before, 0} = DateTime.from_iso8601(only_before <> "T00:00:00Z")
    {:ok, created, 0} = DateTime.from_iso8601(post["created"] <> "Z")
    DateTime.compare(created, only_after) === :gt and DateTime.compare(created, only_before) === :lt
  end

  def matches_title_rule?(_, :whitelist, nil), do: true
  def matches_title_rule?(_, :whitelist, []), do: true
  def matches_title_rule?(_, :blacklist, nil), do: false
  def matches_title_rule?(_, :blacklist, []), do: false
  def matches_title_rule?(post, _, regex_strings) when is_list(regex_strings) do
    regexes = Enum.reduce(regex_strings, [], fn regex_str, acc ->
      case Regex.compile(regex_str) do
         {:ok, regex} -> acc ++ [regex]
         {:error, _} -> acc
      end
    end)
    title = post["title"]
    Enum.reduce(regexes, false, fn regex, acc -> acc or String.match?(title, regex) end)
  end

  def trim_trailing_ms(date) when is_bitstring(date) do
     String.replace(date, ~r/\..+/, "")
  end

  def parse_json_metadata(post) do
     result = case Poison.Parser.parse(post["json_metadata"]) do

defmodule Glasnost.Worker.AuthorSync do
  use GenServer
  alias Glasnost.{Repo, RuntimeConfig, PostFilters, Post}
  import Logger

  def start_link(args, opts \\ []) do
