SET TIMEZONE TO MST;
SHOW integer_datetimes;
 integer_datetimes 
-------------------
 on
(1 row)

CREATE OR REPLACE FUNCTION date_properties(d date) RETURNS setof text LANGUAGE python AS
$python$

def main(d):
	return ['date: ' + str(d)] + [
		': '.join((attname, str(getattr(d, attname))))
		for attname in [
			'millennium',
			'century',
			'decade',
			'year',
			'quarter',
			'week',
			'month',
			'day',
			'dayofweek',
			'dayofyear',
		]
	] + [
		'epoch: {:.3f}'.format(d.epoch)
	]
$python$;
SELECT date_properties('2000-01-01'::date);
   date_properties    
----------------------
 date: 01-01-2000
 millennium: 2
 century: 20
 decade: 200
 year: 2000
 quarter: 1
 week: 52
 month: 1
 day: 1
 dayofweek: 6
 dayofyear: 1
 epoch: 946710000.000
(12 rows)

SELECT date_properties('1000-01-01'::date);
     date_properties     
-------------------------
 date: 01-01-1000
 millennium: 1
 century: 10
 decade: 100
 year: 1000
 quarter: 1
 week: 1
 month: 1
 day: 1
 dayofweek: 3
 dayofyear: 1
 epoch: -30610198800.000
(12 rows)

SELECT date_properties('1000-12-30'::date);
     date_properties     
-------------------------
 date: 12-30-1000
 millennium: 1
 century: 10
 decade: 100
 year: 1000
 quarter: 4
 week: 1
 month: 12
 day: 30
 dayofweek: 2
 dayofyear: 364
 epoch: -30578835600.000
(12 rows)

SELECT date_properties('3000-12-30'::date);
    date_properties     
------------------------
 date: 12-30-3000
 millennium: 3
 century: 30
 decade: 300
 year: 3000
 quarter: 4
 week: 1
 month: 12
 day: 30
 dayofweek: 2
 dayofyear: 364
 epoch: 32535068400.000
(12 rows)

SELECT date_properties('1-1-0001'::date);
     date_properties     
-------------------------
 date: 01-01-0001
 millennium: 1
 century: 1
 decade: 0
 year: 1
 quarter: 1
 week: 1
 month: 1
 day: 1
 dayofweek: 1
 dayofyear: 1
 epoch: -62135571600.000
(12 rows)

CREATE OR REPLACE FUNCTION time_properties(d time) RETURNS setof text LANGUAGE python AS
$python$

def main(d):
	return ['time: ' + str(d)] + [
		': '.join((attname, str(getattr(d, attname))))
		for attname in [
			'hour',
			'minute',
			'second',
			'millisecond',
			'microsecond',
		]
	] + [
		'epoch: {:.3f}'.format(d.epoch)
	]
$python$;
SELECT time_properties('0:0:0.0'::time);
 time_properties 
-----------------
 time: 00:00:00
 hour: 0
 minute: 0
 second: 0
 millisecond: 0
 microsecond: 0
 epoch: 0.000
(7 rows)

SELECT time_properties('23:59:59'::time);
    time_properties    
-----------------------
 time: 23:59:59
 hour: 23
 minute: 59
 second: 59
 millisecond: 59000
 microsecond: 59000000
 epoch: 86399.000
(7 rows)

SELECT time_properties('10:30:00.123'::time);
   time_properties   
---------------------
 time: 10:30:00.123
 hour: 10
 minute: 30
 second: 0
 millisecond: 123
 microsecond: 123000
 epoch: 37800.123
(7 rows)

SELECT time_properties('12:30:35.22222'::time);
    time_properties    
-----------------------
 time: 12:30:35.22222
 hour: 12
 minute: 30
 second: 35
 millisecond: 35222
 microsecond: 35222220
 epoch: 45035.222
(7 rows)

CREATE OR REPLACE FUNCTION timetz_properties(d timetz) RETURNS setof text LANGUAGE python AS
$python$

def main(d):
	return ['timetz: ' + str(d)] + [
		': '.join((attname, str(getattr(d, attname))))
		for attname in [
			'timezone',
			'hour',
			'minute',
			'second',
			'millisecond',
			'microsecond',
		]
	] + [
		'epoch: {:.3f}'.format(d.epoch)
	]
$python$;
SELECT timetz_properties('0:0:0.0'::timetz);
  timetz_properties  
---------------------
 timetz: 00:00:00-07
 timezone: -25200
 hour: 0
 minute: 0
 second: 0
 millisecond: 0
 microsecond: 0
 epoch: 25200.000
(8 rows)

SELECT timetz_properties('23:59:59'::timetz);
   timetz_properties   
-----------------------
 timetz: 23:59:59-07
 timezone: -25200
 hour: 23
 minute: 59
 second: 59
 millisecond: 59000
 microsecond: 59000000
 epoch: 111599.000
(8 rows)

SELECT timetz_properties('10:30:00.123'::timetz);
    timetz_properties    
-------------------------
 timetz: 10:30:00.123-07
 timezone: -25200
 hour: 10
 minute: 30
 second: 0
 millisecond: 123
 microsecond: 123000
 epoch: 63000.123
(8 rows)

SELECT timetz_properties('12:30:35.22222'::timetz);
     timetz_properties     
---------------------------
 timetz: 12:30:35.22222-07
 timezone: -25200
 hour: 12
 minute: 30
 second: 35
 millisecond: 35222
 microsecond: 35222220
 epoch: 70235.222
(8 rows)

SELECT timetz_properties('0:0:0.0+0700'::timetz);
  timetz_properties  
---------------------
 timetz: 00:00:00+07
 timezone: 25200
 hour: 0
 minute: 0
 second: 0
 millisecond: 0
 microsecond: 0
 epoch: -25200.000
(8 rows)

SELECT timetz_properties('0:0:0.0-0700'::timetz);
  timetz_properties  
---------------------
 timetz: 00:00:00-07
 timezone: -25200
 hour: 0
 minute: 0
 second: 0
 millisecond: 0
 microsecond: 0
 epoch: 25200.000
(8 rows)

SELECT timetz_properties('23:59:59+300'::timetz);
   timetz_properties   
-----------------------
 timetz: 23:59:59+03
 timezone: 10800
 hour: 23
 minute: 59
 second: 59
 millisecond: 59000
 microsecond: 59000000
 epoch: 75599.000
(8 rows)

SELECT timetz_properties('23:59:59-300'::timetz);
   timetz_properties   
-----------------------
 timetz: 23:59:59-03
 timezone: -10800
 hour: 23
 minute: 59
 second: 59
 millisecond: 59000
 microsecond: 59000000
 epoch: 97199.000
(8 rows)

SELECT timetz_properties('11:30:00.123+1245'::timetz);
     timetz_properties      
----------------------------
 timetz: 11:30:00.123+12:45
 timezone: 45900
 hour: 11
 minute: 30
 second: 0
 millisecond: 123
 microsecond: 123000
 epoch: -4499.877
(8 rows)

SELECT timetz_properties('15:30:35.22222-0352'::timetz);
      timetz_properties       
------------------------------
 timetz: 15:30:35.22222-03:52
 timezone: -13920
 hour: 15
 minute: 30
 second: 35
 millisecond: 35222
 microsecond: 35222220
 epoch: 69755.222
(8 rows)

CREATE OR REPLACE FUNCTION timestamp_properties(d timestamp) RETURNS setof text LANGUAGE python AS
$python$

def main(d):
	return ['timestamp: ' + str(d)] + [
		': '.join((attname, str(getattr(d, attname))))
		for attname in [
			'millennium',
			'century',
			'decade',
			'year',
			'quarter',
			'week',
			'month',
			'day',
			'hour',
			'minute',
			'second',
			'millisecond',
			'microsecond',
			'dayofweek',
			'dayofyear',
		]
	] + [
		'epoch: {:.3f}'.format(d.epoch)
	]
$python$;
SELECT timestamp_properties('2000-01-01 0:0:0.0'::timestamp);
        timestamp_properties         
-------------------------------------
 timestamp: Sat Jan 01 00:00:00 2000
 millennium: 2
 century: 20
 decade: 200
 year: 2000
 quarter: 1
 week: 52
 month: 1
 day: 1
 hour: 0
 minute: 0
 second: 0
 millisecond: 0
 microsecond: 0
 dayofweek: 6
 dayofyear: 1
 epoch: 946710000.000
(17 rows)

SELECT timestamp_properties('1990-06-01 23:59:59'::timestamp);
        timestamp_properties         
-------------------------------------
 timestamp: Fri Jun 01 23:59:59 1990
 millennium: 2
 century: 20
 decade: 199
 year: 1990
 quarter: 2
 week: 22
 month: 6
 day: 1
 hour: 23
 minute: 59
 second: 59
 millisecond: 59000
 microsecond: 59000000
 dayofweek: 5
 dayofyear: 152
 epoch: 644309999.000
(17 rows)

SELECT timestamp_properties('2020-10-10 10:30:00.123'::timestamp);
          timestamp_properties           
-----------------------------------------
 timestamp: Sat Oct 10 10:30:00.123 2020
 millennium: 3
 century: 21
 decade: 202
 year: 2020
 quarter: 4
 week: 41
 month: 10
 day: 10
 hour: 10
 minute: 30
 second: 0
 millisecond: 123
 microsecond: 123000
 dayofweek: 6
 dayofyear: 284
 epoch: 1602351000.123
(17 rows)

SELECT timestamp_properties('2045-12-20 12:30:35.22222'::timestamp);
           timestamp_properties            
-------------------------------------------
 timestamp: Wed Dec 20 12:30:35.22222 2045
 millennium: 3
 century: 21
 decade: 204
 year: 2045
 quarter: 4
 week: 51
 month: 12
 day: 20
 hour: 12
 minute: 30
 second: 35
 millisecond: 35222
 microsecond: 35222220
 dayofweek: 3
 dayofyear: 354
 epoch: 2397411035.222
(17 rows)

SELECT timestamp_properties('2200-01-01 0:0:0.0'::timestamp);
        timestamp_properties         
-------------------------------------
 timestamp: Wed Jan 01 00:00:00 2200
 millennium: 3
 century: 22
 decade: 220
 year: 2200
 quarter: 1
 week: 1
 month: 1
 day: 1
 hour: 0
 minute: 0
 second: 0
 millisecond: 0
 microsecond: 0
 dayofweek: 3
 dayofyear: 1
 epoch: 7258143600.000
(17 rows)

SELECT timestamp_properties('1000-01-01 0:0:0.0'::timestamp);
        timestamp_properties         
-------------------------------------
 timestamp: Wed Jan 01 00:00:00 1000
 millennium: 1
 century: 10
 decade: 100
 year: 1000
 quarter: 1
 week: 1
 month: 1
 day: 1
 hour: 0
 minute: 0
 second: 0
 millisecond: 0
 microsecond: 0
 dayofweek: 3
 dayofyear: 1
 epoch: -30610198800.000
(17 rows)

SELECT timestamp_properties('1500-02-21 23:59:59'::timestamp);
        timestamp_properties         
-------------------------------------
 timestamp: Wed Feb 21 23:59:59 1500
 millennium: 2
 century: 15
 decade: 150
 year: 1500
 quarter: 1
 week: 8
 month: 2
 day: 21
 hour: 23
 minute: 59
 second: 59
 millisecond: 59000
 microsecond: 59000000
 dayofweek: 3
 dayofyear: 52
 epoch: -14827251601.000
(17 rows)

SELECT timestamp_properties('2499-12-31 23:59:59'::timestamp);
        timestamp_properties         
-------------------------------------
 timestamp: Thu Dec 31 23:59:59 2499
 millennium: 3
 century: 25
 decade: 249
 year: 2499
 quarter: 4
 week: 53
 month: 12
 day: 31
 hour: 23
 minute: 59
 second: 59
 millisecond: 59000
 microsecond: 59000000
 dayofweek: 4
 dayofyear: 365
 epoch: 16725250799.000
(17 rows)

SELECT timestamp_properties('2100-01-01 11:30:00.123'::timestamp);
          timestamp_properties           
-----------------------------------------
 timestamp: Fri Jan 01 11:30:00.123 2100
 millennium: 3
 century: 21
 decade: 210
 year: 2100
 quarter: 1
 week: 53
 month: 1
 day: 1
 hour: 11
 minute: 30
 second: 0
 millisecond: 123
 microsecond: 123000
 dayofweek: 5
 dayofyear: 1
 epoch: 4102511400.123
(17 rows)

SELECT timestamp_properties('2235-01-01 15:30:35.22222'::timestamp);
           timestamp_properties            
-------------------------------------------
 timestamp: Thu Jan 01 15:30:35.22222 2235
 millennium: 3
 century: 23
 decade: 223
 year: 2235
 quarter: 1
 week: 1
 month: 1
 day: 1
 hour: 15
 minute: 30
 second: 35
 millisecond: 35222
 microsecond: 35222220
 dayofweek: 4
 dayofyear: 1
 epoch: 8362650635.222
(17 rows)

CREATE OR REPLACE FUNCTION timestamptz_properties(d timestamptz) RETURNS setof text LANGUAGE python AS
$python$

def main(d):
	return ['timestamptz: ' + str(d)] + [
		': '.join((attname, str(getattr(d, attname))))
		for attname in [
			'timezone',
			'millennium',
			'century',
			'quarter',
			'decade',
			'year',
			'week',
			'month',
			'day',
			'hour',
			'minute',
			'second',
			'millisecond',
			'microsecond',
			'dayofweek',
			'dayofyear',
		]
	] + [
		'epoch: {:.3f}'.format(d.epoch)
	]
$python$;
SELECT timestamptz_properties('2000-01-01 0:0:0.0'::timestamptz);
          timestamptz_properties           
-------------------------------------------
 timestamptz: Sat Jan 01 00:00:00 2000 MST
 timezone: -25200
 millennium: 2
 century: 20
 quarter: 1
 decade: 200
 year: 2000
 week: 52
 month: 1
 day: 1
 hour: 0
 minute: 0
 second: 0
 millisecond: 0
 microsecond: 0
 dayofweek: 6
 dayofyear: 1
 epoch: 946710000.000
(18 rows)

SELECT timestamptz_properties('1990-06-01 23:59:59'::timestamptz);
          timestamptz_properties           
-------------------------------------------
 timestamptz: Fri Jun 01 23:59:59 1990 MST
 timezone: -25200
 millennium: 2
 century: 20
 quarter: 2
 decade: 199
 year: 1990
 week: 22
 month: 6
 day: 1
 hour: 23
 minute: 59
 second: 59
 millisecond: 59000
 microsecond: 59000000
 dayofweek: 5
 dayofyear: 152
 epoch: 644309999.000
(18 rows)

SELECT timestamptz_properties('2020-10-10 10:30:00.123'::timestamptz);
            timestamptz_properties             
-----------------------------------------------
 timestamptz: Sat Oct 10 10:30:00.123 2020 MST
 timezone: -25200
 millennium: 3
 century: 21
 quarter: 4
 decade: 202
 year: 2020
 week: 41
 month: 10
 day: 10
 hour: 10
 minute: 30
 second: 0
 millisecond: 123
 microsecond: 123000
 dayofweek: 6
 dayofyear: 284
 epoch: 1602351000.123
(18 rows)

SELECT timestamptz_properties('2045-12-20 12:30:35.22222'::timestamptz);
             timestamptz_properties              
-------------------------------------------------
 timestamptz: Wed Dec 20 12:30:35.22222 2045 MST
 timezone: -25200
 millennium: 3
 century: 21
 quarter: 4
 decade: 204
 year: 2045
 week: 51
 month: 12
 day: 20
 hour: 12
 minute: 30
 second: 35
 millisecond: 35222
 microsecond: 35222220
 dayofweek: 3
 dayofyear: 354
 epoch: 2397411035.222
(18 rows)

SELECT timestamptz_properties('2200-01-01 0:0:0.0+0800'::timestamptz);
          timestamptz_properties           
-------------------------------------------
 timestamptz: Tue Dec 31 09:00:00 2199 MST
 timezone: -25200
 millennium: 3
 century: 22
 quarter: 4
 decade: 219
 year: 2199
 week: 1
 month: 12
 day: 31
 hour: 9
 minute: 0
 second: 0
 millisecond: 0
 microsecond: 0
 dayofweek: 2
 dayofyear: 365
 epoch: 7258089600.000
(18 rows)

SELECT timestamptz_properties('1000-01-01 0:0:0.0-0800'::timestamptz);
          timestamptz_properties           
-------------------------------------------
 timestamptz: Wed Jan 01 01:00:00 1000 MST
 timezone: -25200
 millennium: 1
 century: 10
 quarter: 1
 decade: 100
 year: 1000
 week: 1
 month: 1
 day: 1
 hour: 1
 minute: 0
 second: 0
 millisecond: 0
 microsecond: 0
 dayofweek: 3
 dayofyear: 1
 epoch: -30610195200.000
(18 rows)

SELECT timestamptz_properties('1500-02-21 23:59:59+300'::timestamptz);
          timestamptz_properties           
-------------------------------------------
 timestamptz: Wed Feb 21 13:59:59 1500 MST
 timezone: -25200
 millennium: 2
 century: 15
 quarter: 1
 decade: 150
 year: 1500
 week: 8
 month: 2
 day: 21
 hour: 13
 minute: 59
 second: 59
 millisecond: 59000
 microsecond: 59000000
 dayofweek: 3
 dayofyear: 52
 epoch: -14827287601.000
(18 rows)

SELECT timestamptz_properties('2499-12-31 23:59:59-300'::timestamptz);
          timestamptz_properties           
-------------------------------------------
 timestamptz: Thu Dec 31 19:59:59 2499 MST
 timezone: -25200
 millennium: 3
 century: 25
 quarter: 4
 decade: 249
 year: 2499
 week: 53
 month: 12
 day: 31
 hour: 19
 minute: 59
 second: 59
 millisecond: 59000
 microsecond: 59000000
 dayofweek: 4
 dayofyear: 365
 epoch: 16725236399.000
(18 rows)

SELECT timestamptz_properties('2100-01-01 11:30:00.123+1245'::timestamptz);
            timestamptz_properties             
-----------------------------------------------
 timestamptz: Thu Dec 31 15:45:00.123 2099 MST
 timezone: -25200
 millennium: 3
 century: 21
 quarter: 4
 decade: 209
 year: 2099
 week: 53
 month: 12
 day: 31
 hour: 15
 minute: 45
 second: 0
 millisecond: 123
 microsecond: 123000
 dayofweek: 4
 dayofyear: 365
 epoch: 4102440300.123
(18 rows)

SELECT timestamptz_properties('2235-01-01 15:30:35.22222-0352'::timestamptz);
             timestamptz_properties              
-------------------------------------------------
 timestamptz: Thu Jan 01 12:22:35.22222 2235 MST
 timezone: -25200
 millennium: 3
 century: 23
 quarter: 1
 decade: 223
 year: 2235
 week: 1
 month: 1
 day: 1
 hour: 12
 minute: 22
 second: 35
 millisecond: 35222
 microsecond: 35222220
 dayofweek: 4
 dayofyear: 1
 epoch: 8362639355.222
(18 rows)

CREATE OR REPLACE FUNCTION interval_properties(d interval) RETURNS setof text LANGUAGE python AS
$python$

def main(d):
	return ['interval: ' + str(d)] + [
		': '.join((attname, str(getattr(d, attname))))
		for attname in [
			'millennium',
			'century',
			'decade',
			'year',
			'quarter',
			'month',
			'day',
			'hour',
			'minute',
			'second',
			'millisecond',
			'microsecond',
		]
	] + [
		'epoch: {:.3f}'.format(d.epoch)
	]
$python$;
SELECT interval_properties('0'::interval);
 interval_properties 
---------------------
 interval: @ 0
 millennium: 0
 century: 0
 decade: 0
 year: 0
 quarter: 1
 month: 0
 day: 0
 hour: 0
 minute: 0
 second: 0
 millisecond: 0
 microsecond: 0
 epoch: 0.000
(14 rows)

SELECT interval_properties('1 second'::interval);
 interval_properties  
----------------------
 interval: @ 1 sec
 millennium: 0
 century: 0
 decade: 0
 year: 0
 quarter: 1
 month: 0
 day: 0
 hour: 0
 minute: 0
 second: 1
 millisecond: 1000
 microsecond: 1000000
 epoch: 1.000
(14 rows)

SELECT interval_properties('1 day'::interval);
 interval_properties 
---------------------
 interval: @ 1 day
 millennium: 0
 century: 0
 decade: 0
 year: 0
 quarter: 1
 month: 0
 day: 1
 hour: 0
 minute: 0
 second: 0
 millisecond: 0
 microsecond: 0
 epoch: 86400.000
(14 rows)

SELECT interval_properties('1 year'::interval);
 interval_properties 
---------------------
 interval: @ 1 year
 millennium: 0
 century: 0
 decade: 0
 year: 1
 quarter: 1
 month: 0
 day: 0
 hour: 0
 minute: 0
 second: 0
 millisecond: 0
 microsecond: 0
 epoch: 31557600.000
(14 rows)

SELECT interval_properties('4 weeks 7 days 2 hours 7 minutes 2 seconds 10232 microseconds'::interval);
             interval_properties              
----------------------------------------------
 interval: @ 35 days 2 hours 7 mins 2.01 secs
 millennium: 0
 century: 0
 decade: 0
 year: 0
 quarter: 1
 month: 0
 day: 35
 hour: 2
 minute: 7
 second: 2
 millisecond: 2010
 microsecond: 2010232
 epoch: 3031622.010
(14 rows)

SELECT interval_properties('1 month'::interval);
 interval_properties 
---------------------
 interval: @ 1 mon
 millennium: 0
 century: 0
 decade: 0
 year: 0
 quarter: 1
 month: 1
 day: 0
 hour: 0
 minute: 0
 second: 0
 millisecond: 0
 microsecond: 0
 epoch: 2592000.000
(14 rows)

SELECT interval_properties('85 years'::interval);
  interval_properties  
-----------------------
 interval: @ 85 years
 millennium: 0
 century: 0
 decade: 8
 year: 85
 quarter: 1
 month: 0
 day: 0
 hour: 0
 minute: 0
 second: 0
 millisecond: 0
 microsecond: 0
 epoch: 2682396000.000
(14 rows)

SELECT interval_properties('1 century'::interval);
  interval_properties  
-----------------------
 interval: @ 100 years
 millennium: 0
 century: 1
 decade: 10
 year: 100
 quarter: 1
 month: 0
 day: 0
 hour: 0
 minute: 0
 second: 0
 millisecond: 0
 microsecond: 0
 epoch: 3155760000.000
(14 rows)

SELECT interval_properties('1 millennium'::interval);
  interval_properties   
------------------------
 interval: @ 1000 years
 millennium: 1
 century: 10
 decade: 100
 year: 1000
 quarter: 1
 month: 0
 day: 0
 hour: 0
 minute: 0
 second: 0
 millisecond: 0
 microsecond: 0
 epoch: 31557600000.000
(14 rows)

SELECT interval_properties('3 months 6 days'::interval);
    interval_properties    
---------------------------
 interval: @ 3 mons 6 days
 millennium: 0
 century: 0
 decade: 0
 year: 0
 quarter: 2
 month: 3
 day: 6
 hour: 0
 minute: 0
 second: 0
 millisecond: 0
 microsecond: 0
 epoch: 8294400.000
(14 rows)

