package com.moandjiezana.toml;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

class DateSerializer implements Serializer {
  static final Serializer DATE_SERIALIZER = new DateSerializer();
  private static final Calendar calendar = new GregorianCalendar();
  private static final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:m:ss");

  @Override
  public boolean canSerialize(Object value) {
    return value instanceof Date;
  }

  @Override
  public void serialize(Object value, SerializerContext context) {
    context.serialized.append(dateFormat.format(value));
    int tzOffset = (calendar.get(Calendar.ZONE_OFFSET) + calendar.get(Calendar.DST_OFFSET)) / (60 * 1000);
    context.serialized.append(String.format("%+03d:%02d", tzOffset / 60, tzOffset % 60));
  }

  @Override
  public boolean isPrimitiveType() {
    return true;
  }

  @Override
  public boolean isTable() {
    return false;
  }
}

@@ -329,107 +329,8 @@
 r();
-%0A  private static final SimpleDateFormat dateFormat = new SimpleDateFormat(%22yyyy-MM-dd'T'HH:m:ss%22);
 %0A%0A  
@@ -499,24 +499,104 @@
  context) %7B%0A
+    SimpleDateFormat dateFormat = new SimpleDateFormat(%22yyyy-MM-dd'T'HH:m:ss%22);%0A
     context.

Fix thread-safety issue in DateSerializer.