package jrequest.base;

import java.text.*;
import java.util.*;



/**
 * User class which represents a user.
 *
 * created at Nov 12, 2002
 * @author daaby
 */

public class User implements Comparable {
   
    private String name;
    private Date birth;
    
    public User(String name) {
        this.name = name;
//        this.setName(name);
    }
    
    public void setName(String name) {
        byte nl = Character.LINE_SEPARATOR;
        this.name = name;
    }
    
    public void setBirth(String s) throws ParseException {
//        this.birth = new SimpleDateFormat("d.M.y").parse(s);
        // date format: dd.mm.yyyy
        int day   = Integer.parseInt(s.substring(0,2));
        int month = Integer.parseInt(s.substring(3,5));
        int year  = Integer.parseInt(s.substring(6,10));
        this.setBirth(year, month, day);
    }
    
    public void setBirth(int year, int month, int day) {
//        this.birth = new GregorianCalendar(year, month-1, day).getTime();
        this.setBirth(
            new GregorianCalendar(year, month-1, day).getTimeInMillis());
    }
    
    public void setBirth(long time) {
        this.setBirth(new Date(time));
    }

    public void setBirth(Date date) {
        this.birth = date;
    }
    
    public void setBirth(int year, int month, int day, int hour, int minute) {
        this.birth =
            new GregorianCalendar(year, month - 1, day, hour, minute).getTime();
    }
    
    public String getName() {
        return this.name;
    }
    
    public Date getBirth() {
        return this.birth;
    }
    
//    public void internalCrashtestDummy() {
//    }
    
    public String toString() {
//        this.internalCrashtestDummy();
        return this.getName() + ", " + this.getBirth();
    }
    
    public int compareTo(Object other) {
        return this.getName().compareToIgnoreCase(other.toString());
    }

}
