
package org.pitest.mutationtest.config;

import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Date;

public class DatedDirectoryReportDirCreationStrategy implements
    ReportDirCreationStrategy {

  public File createReportDir(final String base) {
    final SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmm");
    final String timeString = sdf.format(new Date());
    final File reportDir = new File(addPathSeperatorIfMissing(base)
        + timeString);
    reportDir.mkdirs();
    return reportDir;
  }

  private String addPathSeperatorIfMissing(final String s) {
    if (!s.endsWith(File.separator)) {
      return s + File.separator;
    } else {
      return s;
    }
  }

}
