/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package kanjiflash;

import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.Scanner;

/**
 *
 * @author Alan
 */
public class KanjiHistory {
    public int unicode;
    public Calendar dateUsed;
    public KanjiHistory(int uni, int year, int month, int day){
        dateUsed = new GregorianCalendar(year, month, day);
    }
    public KanjiHistory(int uni, String str){
        unicode = uni;
        int day = 0;
        int month = 0;
        int year = 0;
        boolean error = false;
        if (str.equalsIgnoreCase("0/0/0")){
            dateUsed = new GregorianCalendar(0, 0, 0);
        }
        else {
            String[] inp = new String[3];
            Scanner scn = new Scanner(str);
            scn.useDelimiter("/");
            int k = 0;
            while (scn.hasNext()){
               inp[k++] = scn.next();
            }
            inp[2] = str.substring(str.length()-4);
            try {
                month = Integer.parseInt(inp[0]);
                day = Integer.parseInt(inp[1]);
                year = Integer.parseInt(inp[2]);
            } catch (NumberFormatException e){
                error = true;
            }
            if (!error)
                dateUsed = new GregorianCalendar(year, month, day);
        }
    }
    @Override
    public String toString(){
        return String.format("%d/%d/%d",dateUsed.get(Calendar.MONTH),
                dateUsed.get(Calendar.DAY_OF_MONTH), dateUsed.get(Calendar.YEAR));
    }    
    
}
