Copyright year, optimal approach to keep up to date

Hi,

I was wondering if this is the optimal solution to keeping the copyright year up to date:

@* Get current year for copyright notice *@
@currentYear = @{
  import java.util.Calendar
  import java.text.SimpleDateFormat

  val today = Calendar.getInstance.getTime
  val curTimeFormat = new SimpleDateFormat("Y")

  curTimeFormat.format(today)
}

      <div class="container">
        <div class="row">
          <div class="col-sm-12">
            <hr style="color: white;"/>
            <p style="text-align: center;">Copyright © 2000 - @currentYear example.com. All rights reserved.</p>
          </div>
        </div>
      </div>

Please advise,

Thanks

Have a look at https://github.com/sbt/sbt-header

Play itself uses it to manage it’s file headers:

I you want to do that for your rendered pages instead of code, right?

What you can do is to have this as Java/Scala code (which is easier to test, for example) instead of directly inside the templates:

package helpers

object Views {
  def year: String = java.time.Year.now().toString
}

And in your view:

<p style="text-align: center;">Copyright © 2000 - @{helpers.Views.year} example.com. All rights reserved.</p>

But in this case, the Java Time API is simple enough to not justify this, so I would go with @{java.time.Year.now().toString} directly on the view.