view src/main/java/de/mpiwg/gazetteer/db/DBSectionVersion.java @ 102:6a508b605b5f

1. add new page : footer.jsp. 2. embed footer.jsp into other pages.
author Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
date Fri, 29 Sep 2017 16:03:06 +0200
parents ce2e3f2814c0
children
line wrap: on
line source

package de.mpiwg.gazetteer.db;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.TimeZone;

import org.apache.log4j.Logger;

public class DBSectionVersion implements Comparable<DBSectionVersion>{
	private static Logger logger = Logger.getLogger(DBSectionVersion.class);
	
	private String id;
	private String version;
	private String editor;
	private String date;
	private String books_id;
	
	public DBSectionVersion(ResultSet rs) throws SQLException{
		this.id = rs.getString("id");
		this.version = rs.getString("version");
		this.editor = rs.getString("editor");
		this.date = rs.getString("date");
		this.books_id = rs.getString("books_id");
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getVersion() {
		return version;
	}

	public void setVersion(String version) {
		this.version = version;
	}

	public String getEditor() {
		return editor;
	}

	public void setEditor(String editor) {
		this.editor = editor;
	}

	public String getDate() {
		// TODO optional time zone
		
		// time zone convert
		SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		 
		String dateInString = this.date;
		Date dateBerlin = null;
		try {
			dateBerlin = formatter.parse(dateInString);
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		TimeZone tz = TimeZone.getDefault();
 
		// From TimeZone Europe/Berlin
		/*
		System.out.println("\nOrignal TimeZone");
		System.out.println("TimeZone : " + tz.getID() + " - " + tz.getDisplayName());
		System.out.println("TimeZone : " + tz);
		System.out.println("Date : " + formatter.format(dateBerlin));
		*/
		
		// To TimeZone Asia/Taipei
		SimpleDateFormat sdfTaipei = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		TimeZone tzInTaipei = TimeZone.getTimeZone("Asia/Taipei");	// Asia/Taipei
		sdfTaipei.setTimeZone(tzInTaipei);
 
		String sDateInTaipei = sdfTaipei.format(dateBerlin); // Convert to String first
		Date dateInTaipei = null;
		try {
			dateInTaipei = formatter.parse(sDateInTaipei);
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		/*
		System.out.println("New TimeZone");
		System.out.println("TimeZone : " + tzInTaipei.getID() + " - " + tzInTaipei.getDisplayName());
		System.out.println("TimeZone : " + tzInTaipei);
		System.out.println("Date (String) : " + dateInTaipei);
		System.out.println("Date (Object) : " + formatter.format(dateInTaipei)); 
		*/
		
		return formatter.format(dateInTaipei)+"(UTC+8)";
	}

	public void setDate(String date) {
		this.date = date;
	}

	public String getBooks_id() {
		return books_id;
	}

	public void setBooks_id(String books_id) {
		this.books_id = books_id;
	}

	@Override
	public int compareTo(DBSectionVersion o) {
		return this.getId().compareTo(o.getId());
	
	}
	
	
	
	

}