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

type casting: convert int <-> int64 #620

Closed
dunn opened this issue Nov 7, 2014 · 6 comments
Closed

type casting: convert int <-> int64 #620

dunn opened this issue Nov 7, 2014 · 6 comments
Labels

Comments

@dunn
Copy link
Contributor

dunn commented Nov 7, 2014

This might be related to #255.

Take this template example from the Hugo docs:

<h4>Upcoming Events</h4>
<ul class="upcoming-events">
{{ range where .Data.Pages.ByDate "Section" "events" }}
  {{ if ge .Date.Unix .Now.Unix }}
    <li><span class="event-type">{{ .Type | title }} —</span>
      {{ .Title }}
      on <span class="event-date">
      {{ .Date.Format "2 January at 3:04pm" }}</span>
      at {{ .Params.place }}
    </li>
  {{ end }}
{{ end }}

Suppose I want to trigger the conditional if .Date.Unix plus a day (86,400 seconds) is greater than .Now.Unix. I tried add 86400 .Date.Unix, but I get the following error:

executing "indexes/events.html" at <.Date.Unix>: wrong type for value; expected int; got int64

How do I convert .Date.Unix to int, or 86400 to int64?

@bep
Copy link
Member

bep commented Nov 7, 2014

It would be useful if you posted the sample that DOESN'T work, and not just the working one.

@dunn
Copy link
Contributor Author

dunn commented Nov 7, 2014

Ha, sorry about that. I replaced {{ if ge .Date.Unix .Now.Unix }} with

  {{ if ge (add 86400 .Date.Unix) .Now.Unix }}

@bep
Copy link
Member

bep commented Nov 7, 2014

There has been fixes related to this done on several of the template methods (can't remember which); I just tested your construction on the latest code and it works fine.

@dunn
Copy link
Contributor Author

dunn commented Nov 8, 2014

Awesome, I was thinking I should start running the dev version anyway.

@dunn dunn closed this as completed Nov 8, 2014
@bep
Copy link
Member

bep commented Nov 8, 2014

I should add that @spf13 has made some breaking changes lately, and you might wait until #609 and #610 is merged -- or pull them in yourself if master "blows up in your face".

Good luck -- running the latest version is more fun! Then you can fix stuff.

@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 20, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants