Skip to content

Commit 4fc1d84

Browse files
committed
Added TIMESTAMP function for #2 and test cases
1 parent 635fd86 commit 4fc1d84

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

date_time.sql

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,8 +301,35 @@ CREATE FUNCTION TIMESTAMP(ASECONDS BIGINT)
301301
RETURN
302302
TIMESTAMP(DATE(ASECONDS / (24 * 60 * 60)), TIME(ASECONDS))!
303303

304+
CREATE FUNCTION TIMESTAMP(
305+
AYEAR INTEGER,
306+
AMONTH INTEGER,
307+
ADAY INTEGER,
308+
AHOUR INTEGER,
309+
AMINUTE INTEGER,
310+
ASECOND INTEGER,
311+
AMICROSECOND INTEGER
312+
)
313+
RETURNS TIMESTAMP
314+
SPECIFIC TIMESTAMP2
315+
LANGUAGE SQL
316+
DETERMINISTIC
317+
NO EXTERNAL ACTION
318+
CONTAINS SQL
319+
RETURN
320+
TIMESTAMP(CHAR(
321+
RIGHT(DIGITS(AYEAR), 4) || '-' ||
322+
RIGHT(DIGITS(AMONTH), 2) || '-' ||
323+
RIGHT(DIGITS(ADAY), 2) || ' ' ||
324+
RIGHT(DIGITS(AHOUR), 2) || ':' ||
325+
RIGHT(DIGITS(AMINUTE), 2) || ':' ||
326+
RIGHT(DIGITS(ASECOND), 2) || '.' ||
327+
RIGHT(DIGITS(AMICROSECOND), 6), 26))!
328+
304329
COMMENT ON SPECIFIC FUNCTION TIMESTAMP1
305330
IS 'Constructs a TIMESTAMP from the specified seconds after the epoch. This is the inverse function of SECONDS'!
331+
COMMENT ON SPECIFIC FUNCTION TIMESTAMP2
332+
IS 'Constructs a TIMESTAMP from the specified year, month, day, hours, minutes, seconds, and microseconds'!
306333

307334
-- YEAR_ISO(ADATE)
308335
-------------------------------------------------------------------------------

test.dat

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ TIMESTAMP(86400)
2222
'0001-01-01 00:00:00.000000'
2323
TIMESTAMP(SECONDS('2010-01-01 00:00:01'))
2424
'2010-01-01 00:00:01.000000'
25+
TIMESTAMP(2000, 1, 1, 0, 0, 0, 0)
26+
'2000-01-01 00:00:00.000000'
2527
YEAR_ISO('2010-01-01')
2628
2009
2729
YEAR_ISO('2010-01-04')

0 commit comments

Comments
 (0)