package uk.co.todddavies.website.closure;

import com.google.common.collect.ImmutableMap;
import com.google.inject.Inject;
import com.google.inject.Singleton;
import com.google.template.soy.jbcsrc.api.SoySauce;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@Singleton
final class MinimalistHomeServlet extends HttpServlet {

  private static final String TEMPLATE_NAME = "todddavies.website.minimalisthome";

  private static final long BIRTH_MILLIS = 802224000000L;
  private static final long YEAR_MILLIS = 31556952000L;
  private static final ImmutableMap<String, String> HOME_DATA = ImmutableMap.of(
      "age", String.valueOf((System.currentTimeMillis() - BIRTH_MILLIS) / YEAR_MILLIS));

  private final SoySauce soySauce;

  @Inject
  private MinimalistHomeServlet(SoySauce soySauce) {
    this.soySauce = soySauce;
  }

  @Override
  public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
    resp.getWriter().print(soySauce.renderTemplate(TEMPLATE_NAME).setData(HOME_DATA).renderHtml().get().getContent());
  }
}

@@ -364,16 +364,69 @@
 ception;
+%0Aimport java.time.LocalDate;%0Aimport java.time.Period;
 %0A%0A@Singl
@@ -570,17 +570,16 @@
 thome%22;%0A
-%0A
   privat
@@ -597,266 +597,56 @@
 nal 
-long BIRTH_MILLIS = 802224000000L;%0A  private static final long YEAR_MILLIS = 31556952000L;%0A  private static final ImmutableMap%3CString, String%3E HOME
+LocalDate BIRTH
 _DAT
-A = ImmutableMap.of(%0A      %22age%22, String.valueOf((System.currentTimeMillis() - BIRTH_MILLIS) / YEAR_MILLIS)
+E = LocalDate.of(1995, 06, 04
 );%0A%0A
@@ -890,88 +890,234 @@
     
-resp.getWriter().print(soySauce.renderTemplate(TEMPLATE_NAME).setData(HOME_DATA)
+int yearsOld = Period.between(BIRTH_DATE, LocalDate.now()).getYears();%0A    resp.getWriter().print(%0A        soySauce%0A            .renderTemplate(TEMPLATE_NAME)%0A            .setData(ImmutableMap.of(%22age%22, yearsOld))%0A            
 .ren

Clean up the computation of my age by switching to Java 8 API's.