diff options
author | href <href@random.sh> | 2021-09-07 15:32:34 +0200 |
---|---|---|
committer | href <href@random.sh> | 2021-09-07 15:34:41 +0200 |
commit | 178cb9aa422893db3ec5cebdfc991381b8bcf1cf (patch) | |
tree | e8d0c81318d1327f5484350f083ef98d51798e2b /lib/lsg_irc | |
parent | update telegram, alcolog fix (diff) |
alcoolog: time migration
Diffstat (limited to 'lib/lsg_irc')
-rw-r--r-- | lib/lsg_irc/alcolog_plugin.ex | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/lib/lsg_irc/alcolog_plugin.ex b/lib/lsg_irc/alcolog_plugin.ex index f00f7f4..8a7bcb9 100644 --- a/lib/lsg_irc/alcolog_plugin.ex +++ b/lib/lsg_irc/alcolog_plugin.ex @@ -66,14 +66,26 @@ defmodule LSG.IRC.AlcoologPlugin do {:ok, meta} = :dets.open_file(dets_meta_filename, [{:type,:set}]) traverse_fun = fn(obj, dets) -> case obj do + object = {nick, naive = %NaiveDateTime{}, volumes, active, cl, deg, name, comment, meta} -> + date = naive + |> DateTime.from_naive!("Etc/UTC") + |> DateTime.to_unix() + new = {nick, date, volumes, active, cl, deg, name, comment, Map.new()} + :dets.delete_object(dets, object) + :dets.insert(dets, new) + :ets.insert(ets, {{nick, date}, volumes, active, cl, deg, name, comment, Map.new()}) + dets + object = {nick, date, volumes, active, cl, deg, name, comment, meta} -> :ets.insert(ets, {{nick, date}, volumes, active, cl, deg, name, comment, meta}) dets + _ -> dets end end :dets.foldl(traverse_fun, dets, dets) + :dets.sync(dets) state = %{dets: dets, meta: meta, ets: ets} {:ok, state} end |