/*
 * Copyright 2013 Yuichiro Moriguchi
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package net.morilib.awk.nano.strftime;

import java.io.IOException;
import java.io.Writer;
import java.text.SimpleDateFormat;
import java.util.Date;

public class StrftimeSimpleDateAction implements StrftimeAction {

	/**
	 * 
	 */
	public static final StrftimeAction ACTION_a =
		new StrftimeSimpleDateAction("EEE");

	/**
	 * 
	 */
	public static final StrftimeAction ACTION_A =
		new StrftimeSimpleDateAction("EEEE");

	/**
	 * 
	 */
	public static final StrftimeAction ACTION_b =
		new StrftimeSimpleDateAction("MMM");

	/**
	 * 
	 */
	public static final StrftimeAction ACTION_B =
		new StrftimeSimpleDateAction("MMMM");

	/**
	 * 
	 */
	public static final StrftimeAction ACTION_d =
		new StrftimeSimpleDateAction("dd");

	/**
	 * 
	 */
	public static final StrftimeAction ACTION_H =
		new StrftimeSimpleDateAction("HH");

	/**
	 * 
	 */
	public static final StrftimeAction ACTION_I =
		new StrftimeSimpleDateAction("hh");

	/**
	 * 
	 */
	public static final StrftimeAction ACTION_m =
		new StrftimeSimpleDateAction("MM");

	/**
	 * 
	 */
	public static final StrftimeAction ACTION_M =
		new StrftimeSimpleDateAction("mm");

	/**
	 * 
	 */
	public static final StrftimeAction ACTION_p =
		new StrftimeSimpleDateAction("a");

	/**
	 * 
	 */
	public static final StrftimeAction ACTION_S =
		new StrftimeSimpleDateAction("ss");

	/**
	 * 
	 */
	public static final StrftimeAction ACTION_y =
		new StrftimeSimpleDateAction("yy");

	/**
	 * 
	 */
	public static final StrftimeAction ACTION_Y =
		new StrftimeSimpleDateAction("yyyy");

	/**
	 * 
	 */
	public static final StrftimeAction ACTION_Z =
		new StrftimeSimpleDateAction("z");

	/**
	 * 
	 */
	public static final StrftimeAction ACTION_D =
		new StrftimeSimpleDateAction("MM/dd/yy");

	/**
	 * 
	 */
	public static final StrftimeAction ACTION_r =
		new StrftimeSimpleDateAction("hh:mm:ss a");

	/**
	 * 
	 */
	public static final StrftimeAction ACTION_R =
		new StrftimeSimpleDateAction("HH:mm");

	/**
	 * 
	 */
	public static final StrftimeAction ACTION_T =
		new StrftimeSimpleDateAction("HH:mm:ss");

	/**
	 * 
	 */
	public static final StrftimeAction ACTION_C =
		new StrftimeSimpleDateAction("yy");

	/**
	 * 
	 */
	public static final StrftimeAction ACTION_V =
		new StrftimeSimpleDateAction("ww");

	/**
	 * 
	 */
	public static final StrftimeAction ACTION_z =
		new StrftimeSimpleDateAction("Z");

	private SimpleDateFormat fmt;

	public StrftimeSimpleDateAction(String format) {
		fmt = new SimpleDateFormat(format);
	}

	public void action(Writer writer,
			Date date) throws IOException {
		writer.append(fmt.format(date.getTime()));
	}

}
