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

Add now macro method #2638

Closed
wants to merge 1 commit into from
Closed

Add now macro method #2638

wants to merge 1 commit into from

Conversation

asterite
Copy link
Member

This adds a now(format, utc = false) macro method that returns Time.now, or Time.utc_now formatter according to the give format.

This can be useful to paste the build time of a program into the executable, and it's more portable than shelling out and using date.

@bcardiff
Copy link
Member

I like the functionality but it is "surprising" that the best approach to accomplish this is to make it built-in in the language.

@asterite
Copy link
Member Author

Well, one can write a small program that does puts Time.now.to_s(ARGV[0]) and then invoke that program with the run macro call, but I think that wanting the build date at compile time is something that's useful to have. We also have the env macro call, which again can be accomplished with run. I think everything can be accomplished with run, but some use cases are more frequent and maybe deserve a built-in.

@bcardiff
Copy link
Member

Yeah, maybe I dislike that the code that interprets the macro differs to much from that Time.now.to_s. If there would be a way to grab real crystal code and specialize it in a macro so the execute_now is generated it would be more maintainable IMO (Crystal -> Macro).

But do not keep back on merging this :-) I am just thinking out loud and sharing weird ideas here.

@asterite
Copy link
Member Author

@bcardiff I've been thinking of a better way to do this: #2639

@asterite
Copy link
Member Author

asterite commented Jun 2, 2016

With #2639, I'm not sure I'd like to merge this. One can also use date inside a macro, we are using it for the compiler and it works well. So I'll close this.

@asterite asterite closed this Jun 2, 2016
@asterite asterite deleted the feature/macro_now branch April 27, 2018 21:18
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

Successfully merging this pull request may close these issues.

None yet

2 participants