maennchen / crontab

:alarm_clock: Parse Cron Expressions, Compose Cron Expression Strings and Caluclate Execution Dates.
https://hex.pm/packages/crontab
MIT License
93 stars 33 forks source link

how can I use this CronExpression ecto type ? #83

Closed siddhant3030 closed 3 years ago

siddhant3030 commented 3 years ago

hi, I have one question.

1:- If I pass the cron_expression like this " ". It's saving as a struct in my database. Something like this ~e[/21 *]. But in order to consume from the frontend, I need to convert this struct to some other type.

So I tried this

  1. CronExpression.to_condition_list(availability.cron_expression) and this will give me something like this
[
  minute: [{:/, :*, 21}],
  hour: [:*],
  day: [:*],
  month: [:*],
  weekday: [:*],
  year: [:*]
]

but I'm not able to pass this in a JSON. In order to consume this, what data should I send? What should I do with struct?

Right now I'm getting this error when I'm trying to send after using the to_condition_list function.

** (Protocol.UndefinedError) protocol Jason.Encoder not implemented for {:minute, [{:/, :*, 21}]} of type Tuple, Jason.Encoder protocol must always be explicitly implemented.