Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Default value for time/dates? #19

Open
brandonparsons opened this issue Apr 14, 2017 · 2 comments
Open

Default value for time/dates? #19

brandonparsons opened this issue Apr 14, 2017 · 2 comments

Comments

@brandonparsons
Copy link

brandonparsons commented Apr 14, 2017

Is there any way to specify a default value for a field of type time? e..g Set ~T[16:30:00] as a default value?

I tried:

[field: :time, default: ~T[16:30:00]]

But it throws an error: ** (CompileError) nofile: invalid quoted expression: ~T[16:30:00]

@vasspilka
Copy link

It should be possible to use the full syntax of the time in the default (below), the error was due to macro compilation issues.

  %Time{
  calendar: Calendar.ISO,
  hour: 16,
  microsecond: {0, 0},
  minute: 30,
  second: 0
}

@dimakula
Copy link

I had a similar issue, I tried using %Time{} and Time.new/3 directly but it came back with the same error. The error message may have improved since this was reported, because it also contains the solution:

Please make sure your quoted expressions are made of valid AST nodes. If you would like to introduce a value into the AST, such as a four-element tuple or a map, make sure to call Macro.escape/1 before

Just wrap the time inside of a Macro.escape/1 call and it will work:

[field: :time, default: Macro.escape(~T[16:30:00])]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants