Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /* ************************************************************************
  #
  #  DivConq
  #
  #  http://divconq.com/
  #
  #  Copyright:
  #    Copyright 2014 eTimeline, LLC. All rights reserved.
  #
 #  License:
 #    See the license.txt file in the project's top-level directory for details.
 #
 #  Authors:
 #    * Andy White
 #
 ************************************************************************ */
 package divconq.lang;
 
 
BigDateTime can handle dates into the billions of years, both past and future. It is used to store dates in the database (dcDb) and for sorting. It is not (yet) useful for date manipulation, for most common date manipulation use the Joda (provided with DivConq) instead. This is designed to be a versatile way to handle historical data. Dates are based off proleptic Gregorian, time is optional but if present then is based off UTC zone. If only date is present then it is assumed to be incomplete and not zone based. Only year is required. Year may be 0 - 99,999,999,999. However, DivConq treats year 50,000,000,001 as 1 CE (aka AD). Therefore if you wish to refer to a Common Era (AD) date then add 50 billion to the year. If you wish to refer to a BCE (aka BC) date then subtract that year from 50,000,000,001. So 1 BCE is 50,000,000,000. Year is 11 digits, 0 padded. Month is optional, if missing then it is understood that the date is for "sometime this year". Month is in traditional 01 - 12 format. Day is optional, if missing but month is present then the date is for "sometime this month". Day is in traditional 01 - 31 format. Hour is optional, if missing but day is present then the date is for "sometime this day" and is not linked to a timezone. If an hour is present it must be in UTC time. Hour is in traditional 00 - 23 format. Minute is optional, if missing but hour is present then the date is for "sometime this hour" and is linked to the UTC timezone. If an minute is present it must be in UTC time. Minute is in traditional 00 - 59 format. Second is optional, if missing but minute is present then the date is for "sometime this minute" and is linked to the UTC timezone. Second is in traditional 00 - 59 format. Internal format of datetime is "tYYYYYYYYYYYMMDDhhmmss". For example, Sept 2004 is "t5000000200409". BigDateTime does not carry any information about which TimeZone it was translated from for which Chronology (Calendar) it was converted from. Always use strict UTC and proleptic Gregorian conversions so that all dates collate/index correctly relative to each other.
 
 public class BigDateTime {
 	protected Long year = null;
 	protected Integer month = null;
 	protected Integer day = null;
 	protected Integer hour = null;
 	protected Integer minute = null;
 	protected Integer second = null;
 	
 	public Long getYear() {
 		return this.;
 	}
 	
 	public Integer getMonth() {
 		return this.;
 	}
 	
 	public Integer getDay() {
 		return this.;
 	}
 	
 	public Integer getHour() {
 		return this.;
 	}
 	
 	public Integer getMinute() {
 		return this.;
 	}
 	
 	public Integer getSecond() {
 		return this.;
	}

Creates an empty, and invalid, datetime.
	public BigDateTime() {
		this(new DateTime());
	}

Parameters:
date translates into BigDateTime
	public BigDateTime(DateTime date) {
		if (date == null)
			return;
		// make sure we are using ISO and UTC
		date = date.toDateTime(ISOChronology.getInstanceUTC());
		//date = date.toDateTime(DateTimeZone.UTC);		
		this. = 50000000000L + date.getYear();		// ISO says 1 BCE = 0, 2 BCE = -1, etc
		this. = date.getMonthOfYear();
		this. = date.getDayOfMonth();
		this. = date.getHourOfDay();
		this. = date.getMinuteOfHour();
		this. = date.getSecondOfMinute();
	}

Parameters:
date translates into BigDateTime, assumes ISOChronology
	public BigDateTime(LocalDate date) {
		if (date == null)
			return;
		this. = 50000000000L + date.getYear();		// ISO says 1 BCE = 0, 2 BCE = -1, etc
		this. = date.getMonthOfYear();
		this. = date.getDayOfMonth();
	}

Parameters:
year where 1 = 1 CE (AD), 0 = 1 BCE (BC)
	public BigDateTime(long year) {
		if ((year < -50000000000L) || (year > 49999999999L))
			return;
		this. = 50000000000L + year;		// ISO says 1 BCE = 0, 2 BCE = -1, etc
	}

Parameters:
year where 1 = 1 CE (AD), 0 = 1 BCE (BC)
month where 1 = Jan
	public BigDateTime(long yearint month) {
		this(year);
		if ((month < 1) || (month > 12))
			return;
		this. = month;
	}

Parameters:
year where 1 = 1 CE (AD), 0 = 1 BCE (BC)
month where 1 = Jan
day of month
	public BigDateTime(long yearint monthint day) {
		this(yearmonth);
		if ((day < 1) || (day > 31))		// not 100% accurate, but ballpark
			return;
		this. = day;
	}

Parameters:
year where 1 = 1 CE (AD), 0 = 1 BCE (BC)
month where 1 = Jan
day of month
hour of day
	public BigDateTime(long yearint monthint dayint hour) {
		this(yearmonthday);
		if ((hour < 0) || (hour > 23))
			return;
		this. = hour;
	}

Parameters:
year where 1 = 1 CE (AD), 0 = 1 BCE (BC)
month where 1 = Jan
day of month
hour of day
minute of hour
	public BigDateTime(long yearint monthint dayint hourint minute) {
		this(yearmonthdayhour);
		if ((minute < 0) || (minute > 59))
			return;
		this. = minute;
	}

Parameters:
year where 1 = 1 CE (AD), 0 = 1 BCE (BC)
month where 1 = Jan
day of month
hour of day
minute of hour
second of minute
	public BigDateTime(long yearint monthint dayint hourint minuteint second) {
		this(yearmonthdayhourminute);
		if ((second < 0) || (second > 59))
			return;
		this. = second;
	}

Returns:
in internal format
	public String toString() {
		if (this. == null)
			return null;
		String res = "t" + StringUtil.leftPad(this. + "", 11, '0');
		if (this. != null) {
			res += StringUtil.leftPad(this. + "", 2, '0');
			if (this. != null) {
				res += StringUtil.leftPad(this. + "", 2, '0');
				if (this. != null) {
					res += StringUtil.leftPad(this. + "", 2, '0');
					if (this. != null) {
						res += StringUtil.leftPad(this. + "", 2, '0');
						if (this. != null
							res += StringUtil.leftPad(this. + "", 2, '0');
					}
				}
			}
		}
		return res;
	}
	static public BigDateTime nowDateTime() {
		return new BigDateTime(new DateTime());
	}
	static public BigDateTime nowDate() {
		return new BigDateTime(new LocalDate());
	}

Parameters:
date internal big datetime format
Returns:
BigDateTime object plus warnings, if any
	static public FuncResult<BigDateTimeparse(String date) {
		if (StringUtil.isEmpty(date)) {
			fr.errorTr(230);
			return fr;
		}
		DataType dt = ..getSchema().getType("BigDateTime");
		if (dt == null) {
			fr.errorTr(232);
			return fr;
		}
		CoreType ct = dt.getCoreType();
		if (ct == null) {
			fr.errorTr(232);
			return fr;
		}
		if (!ct.validate(datefr)) {
			fr.errorTr(231, date);
			return fr;
		}
		BigDateTime bd = new BigDateTime();
		fr.setResult(bd);
		bd.year = Long.parseLong(date.substring(1, 12));
		if (date.length() > 12)
			bd.month = Integer.parseInt(date.substring(12, 14));
		if (date.length() > 14)
			bd.day = Integer.parseInt(date.substring(14, 16));
		if (date.length() > 16)
			bd.hour = Integer.parseInt(date.substring(16, 18));
		if (date.length() > 18)
			bd.minute = Integer.parseInt(date.substring(18, 20));
		if (date.length() > 20)
			bd.second = Integer.parseInt(date.substring(20, 22));
		return fr;
	}
New to GrepCode? Check out our FAQ X