Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- % Functor applicator. Functor returns turple passed with some elem
- % wrapped into fun-parameter.
- %
- on_fst(F) -> fun ({A, B}) -> { F(A), B } end.
- on_snd(F) -> fun ({A, B}) -> { A, F(B) } end.
- % Datetime-structure clearers.
- %
- zero_1() -> fun ({A, B, _}) -> { A, B, 0 } end.
- zero_2() -> fun ({A, _, _}) -> { A, 0, 0 } end.
- zero_3() -> fun ({_, _, _}) -> { 0, 0, 0 } end.
- % Returns the functor, clamping datetime to candle start.
- %
- candle_open(Scale) ->
- case Scale of
- minute -> c([ on_fst(id()), on_snd(zero_1()) ]);
- hour -> c([ on_fst(id()), on_snd(zero_2()) ]);
- day -> c([ on_fst(id()), on_snd(zero_3()) ]);
- month -> c([ on_fst(zero_1()), on_snd(zero_3()) ]);
- week -> c([ on_fst(open_week()), on_snd(zero_3()) ])
- end.
- % Returns the functor clamping date to week start.
- %
- open_week() ->
- fun (Date) ->
- Seconds = t({ Date, { 0, 0, 0} }),
- WeekStart = Seconds - (calendar:day_of_the_week(Date) - 1) * 24 * 60 * 60,
- { NewDate, _ } = un_t(WeekStart),
- NewDate
- end.
- % Returns property selector from some datetime.
- %
- property(Scale) ->
- fun (Trade) ->
- {{Y, Mth, D}, {H, M, _S}} = Trade#trade.point,
- case Scale of
- minute -> M;
- hour -> H;
- day -> D;
- month -> Mth;
- week -> calendar:iso_week_number({Y, Mth, D})
- end
- end.
- % Datetime to second (and back) converters.
- %
- t (GregTime) -> calendar:datetime_to_gregorian_seconds(GregTime).
- un_t(Datetime) -> calendar:gregorian_seconds_to_datetime(Datetime).
Add Comment
Please, Sign In to add comment