package com.perpetumobile.bit.orm.record.field;

import java.nio.ByteBuffer;
import java.sql.Timestamp;

/**
 * @author Zoran Dukic
 *
 */
public class UnixSQLTimestampField extends LongField {
	
	public UnixSQLTimestampField(String fieldName) {
		super(fieldName);
	}
	
	public UnixSQLTimestampField(String fieldName, long value) {
		super(fieldName, value);
	}
	
	public UnixSQLTimestampField(String fieldName, Timestamp value) {
		super(fieldName, value.getTime() / 1000);
	}
	
	public UnixSQLTimestampField(ByteBuffer fieldName) {
		super(fieldName);
	}
	
	public UnixSQLTimestampField(ByteBuffer fieldName, long value) {
		super(fieldName, value);
	}
	
	public UnixSQLTimestampField(ByteBuffer fieldName, Timestamp value) {
		super(fieldName, value.getTime() / 1000);
	}
	
	public String getFieldValue() {
		Timestamp t = new Timestamp(value * 1000);
		return t.toString();
	}
	
	protected void setFieldValueImpl(String fieldValue) {
		Timestamp t = Timestamp.valueOf(fieldValue);
		if(t != null) {
			value = t.getTime() / 1000;
		}
	}
	
	public Timestamp getTimestampFieldValue() {
		return new Timestamp(value * 1000);
	}
		
	protected void setTimestampFieldValueImpl(Timestamp fieldValue) {
		value = fieldValue.getTime() / 1000;
	}
}

@@ -98,16 +98,57 @@
 stamp;%0A%0A
+import com.perpetumobile.bit.util.Util;%0A%0A
 /**%0A * @
@@ -969,24 +969,82 @@
 eldValue) %7B%0A
+%09%09value = Util.toLong(fieldValue, -1);%0A%09%09if(value %3C 0) %7B%0A%09
 %09%09Timestamp 
@@ -1078,16 +1078,17 @@
 Value);%0A
+%09
 %09%09if(t !
@@ -1100,16 +1100,17 @@
 l) %7B%0A%09%09%09
+%09
 value = 
@@ -1129,16 +1129,21 @@
 / 1000;%0A
+%09%09%09%7D%0A
 %09%09%7D%0A%09%7D%0A%09

support text representation of long value