/
area/
classes/net/sourceforge/pain/logic/
classes/net/sourceforge/pain/logic/event/
classes/net/sourceforge/pain/logic/fn/util/
classes/net/sourceforge/pain/network/console/
classes/net/sourceforge/pain/plugin/
classes/net/sourceforge/pain/plugin/reset/
classes/net/sourceforge/pain/plugin/shutdown/
classes/net/sourceforge/pain/plugin/social/
classest/net/sourceforge/pain/db/data/
doc/
doc/paindb/resources/
src/net/sourceforge/pain/logic/
src/net/sourceforge/pain/logic/event/
src/net/sourceforge/pain/logic/fn/util/
src/net/sourceforge/pain/network/console/
src/net/sourceforge/pain/network/console/telnet/
src/net/sourceforge/pain/plugin/
src/net/sourceforge/pain/plugin/command/
src/net/sourceforge/pain/plugin/reset/
src/net/sourceforge/pain/plugin/shutdown/
src/net/sourceforge/pain/plugin/social/
src/net/sourceforge/pain/util/
tests/
tests/net/sourceforge/pain/db/data/
package net.sourceforge.pain.logic.event.console.command;

import net.sourceforge.pain.logic.event.console.*;
import net.sourceforge.pain.logic.fn.*;
import net.sourceforge.pain.logic.fn.util.*;
import net.sourceforge.pain.*;

public final class DateTime extends CommandHandler {

	public void processCommand() throws Exception {
		WorldCalendar time = new WorldCalendar(Core.getTime().getTime());
		int day = time.day + 1;

		if (!"DATE".equals(command.tag)) {
			String str = "It is " + ((time.hour == 12 || time.hour == 0) ? 12 : time.hour % 12) +
			        " o'clock " + (time.hour >= 12 ? "pm" : "am") +
			        ", Day of " + WorldCalendar.dayNames[time.dayOfWeek] +
			        ", " + day + getSuffix(day) +
			        " the Month of " + WorldCalendar.monthNames[time.month] + ".\n";

			MessageOutFn.out(console, str);
			MessageOutFn.outOne(super.player, "It's $t.",
			        (time.hour >= 5 && time.hour < 9) ? "dawn" :
			        (time.hour >= 9 && time.hour < 12) ? "morning" :
			        (time.hour >= 12 && time.hour < 18) ? "mid-day" :
			        (time.hour >= 18 && time.hour < 21) ? "evening" :
			        "night");
		} else {
			String str = "Day of " + WorldCalendar.dayNames[time.dayOfWeek] +
			        ", " + day + getSuffix(day) +
			        " the Month of " + WorldCalendar.monthNames[time.month] + ". " + time.year + " A.D.\n";

			MessageOutFn.out(console, str);
		}
	}

	private static String getSuffix(int number) {
		if (number > 4 && number < 20) {
			return "th";
		} else if (number % 10 == 1) {
			return "st";
		} else if (number % 10 == 2) {
			return "nd";
		} else if (number % 10 == 3) {
			return "rd";
		} else {
			return "th";
		}
	}

	public void showHelp() {
		if ("DATE".equals(command.tag)) {
			MessageOutFn.outln(console, command.name+": shows current date");
		} else { // time
			MessageOutFn.outln(console, command.name+": shows current day time");
		}
	}
}