How to: DateTime validation with compare/2
Im trying to compare datetime in an action with compare/2. Code looks like this:
Weird thing is this validation fails even when resumes_at is in the future. Does this work or are there other ways of easily comparing datetimes in inline changes?
4 Replies
Interesting...we probably need to make
compare
use Comp
🙂
You can always create a manual validation
oh, actually, in your case, DateTime.utc_now(:microsecond)
is always "when the app was compiled"
because its in the compile time DSL
I'd suggest
Then you can say validate {DateInFuture, field: :resumes_at}, where: [present(:resumes_at)]
Doesnt look like
fetch_argument_or_attribute
exists, should I be using get_argument_or_attribute?ah, yeah, you can do that 👍
it will return
nil
or the value, though
otherwise it would be like case fetch_argument(...), .... case fetch_attribute(....), ...
Thanks, this worked! 🙏