changeset 25:86694755415d

new: convert shown edit time to UTC+8
author Zoe Hong <zhong@mpiwg-berlin.mpg.de>
date Fri, 26 Jun 2015 11:32:33 +0200
parents 07f7594ba56e
children ce2e3f2814c0
files src/main/java/de/mpiwg/gazetteer/db/DBSectionVersion.java src/main/resources/config.properties src/main/resources/hibernate.cfg.xml
diffstat 3 files changed, 57 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/src/main/java/de/mpiwg/gazetteer/db/DBSectionVersion.java	Thu Jun 25 10:53:52 2015 +0200
+++ b/src/main/java/de/mpiwg/gazetteer/db/DBSectionVersion.java	Fri Jun 26 11:32:33 2015 +0200
@@ -2,8 +2,16 @@
 
 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;
@@ -44,7 +52,53 @@
 	}
 
 	public String getDate() {
-		return date;
+		// TODO time zone convert
+		// TODO optional time zone
+		
+		
+		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) {
--- a/src/main/resources/config.properties	Thu Jun 25 10:53:52 2015 +0200
+++ b/src/main/resources/config.properties	Fri Jun 26 11:32:33 2015 +0200
@@ -1,5 +1,5 @@
 db_gazetter_username=root
-db_gazetter_password=admin
+db_gazetter_password=root
 db_gazetter_name=Gazetteer
 files_root=/gazetteer-server/data
 
--- a/src/main/resources/hibernate.cfg.xml	Thu Jun 25 10:53:52 2015 +0200
+++ b/src/main/resources/hibernate.cfg.xml	Fri Jun 26 11:32:33 2015 +0200
@@ -17,7 +17,7 @@
         <property name="hibernate.connection.url">jdbc:mysql://localhost/LGServices?characterEncoding=UTF-8</property>
         
         <property name="hibernate.connection.username">root</property>
-		<property name="hibernate.connection.password">admin</property>
+		<property name="hibernate.connection.password">root</property>
 		<property name="hibernate.connection.charSet">UTF-8</property>
 		
 		<!-- JDBC connection pool (use the built-in) -->