11/*-------------------------------------------------------------------------
22 * Copyright 2025 IvorySQL Global Development Team
3- *
3+ *
44 * Licensed under the Apache License, Version 2.0 (the "License");
55 * you may not use this file except in compliance with the License.
66 * You may obtain a copy of the License at
7- *
7+ *
88 * http://www.apache.org/licenses/LICENSE-2.0
9- *
9+ *
1010 * Unless required by applicable law or agreed to in writing, software
1111 * distributed under the License is distributed on an "AS IS" BASIS,
1212 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -160,22 +160,30 @@ timestamp2timestamptz(Timestamp timestamp)
160160 * USER I/O ROUTINES *
161161 *****************************************************************************/
162162
163- /* oradate_in()
164- * Convert a string to internal form.
163+ /**
164+ * Parse textual representation of an Oracle DATE into an internal oradate value.
165+ *
166+ * When the NLS date format is "pg" or datetime NLS handling is disabled, delegates
167+ * to the date/date_timestamp input path. Otherwise parses the input according to
168+ * the current NLS date format, discards any time zone information, and truncates
169+ * fractional seconds to produce an oradate (date-only Timestamp).
170+ *
171+ * @returns A Datum containing the parsed oradate Timestamp.
172+ * @throws ERRCODE_DATETIME_VALUE_OUT_OF_RANGE if the resulting timestamp is out of range.
165173 */
166174Datum
167175oradate_in (PG_FUNCTION_ARGS )
168176{
169- char * str = PG_GETARG_CSTRING (0 );
170- Oid collid = PG_GET_COLLATION ();
177+ char * str = PG_GETARG_CSTRING (0 );
178+ Oid collid = PG_GET_COLLATION ();
171179 Timestamp result ;
172- struct pg_tm tm ;
180+ struct pg_tm tm ;
173181 fsec_t fsec ;
174182
175183 if (strcmp (nls_date_format , "pg" ) == 0 || DATETIME_IGNORE_NLS (datetime_ignore_nls_mask , ORADATE_MASK ))
176184 {
177185 return DirectFunctionCall1 (date_timestamp ,
178- DirectFunctionCall1 (date_in , CStringGetDatum (str )));
186+ DirectFunctionCall1 (date_in , CStringGetDatum (str )));
179187 }
180188 else
181189 {
@@ -192,8 +200,15 @@ oradate_in(PG_FUNCTION_ARGS)
192200 }
193201}
194202
195- /* oradate_out()
196- * Convert a oradate to external form.
203+ /**
204+ * Format an Oracle-compatible DATE value as a C string according to the current NLS date format.
205+ *
206+ * When the configured NLS date format is "pg", the function produces the platform's default
207+ * PostgreSQL timestamp text representation. For any other NLS pattern, the function formats
208+ * the input oradate using that pattern (fractional seconds truncated) and returns the result
209+ * as a C string Datum.
210+ *
211+ * @returns A C string Datum containing the formatted date according to the active NLS format.
197212 */
198213Datum
199214oradate_out (PG_FUNCTION_ARGS )
@@ -206,8 +221,8 @@ oradate_out(PG_FUNCTION_ARGS)
206221 text * date_str ;
207222
208223 date_str = DatumGetTextP (DirectFunctionCall2 (timestamp_to_char ,
209- TimestampGetDatum (timestamp ),
210- PointerGetDatum (cstring_to_text (nls_date_format ))));
224+ TimestampGetDatum (timestamp ),
225+ PointerGetDatum (cstring_to_text (nls_date_format ))));
211226
212227 result = text_to_cstring (date_str );
213228 PG_RETURN_CSTRING (result );
@@ -576,6 +591,16 @@ oradate_cmp_oratimestamptz(PG_FUNCTION_ARGS)
576591 PG_RETURN_INT32 (timestamp_cmp_internal (dt1 , dt2 ));
577592}
578593
594+ /**
595+ * Compare an Oracle DATE value to an Oracle TIMESTAMP WITH LOCAL TIME ZONE value.
596+ *
597+ * The first argument (internal Timestamp) is converted to a TimestampTz before comparison;
598+ * the function then returns an integer indicating the ordering between the converted first
599+ * operand and the second TimestampTz operand.
600+ *
601+ * @returns An integer less than, equal to, or greater than zero if the first operand is
602+ * respectively less than, equal to, or greater than the second operand.
603+ */
579604Datum
580605oradate_cmp_oratimestampltz (PG_FUNCTION_ARGS )
581606{
@@ -588,9 +613,11 @@ oradate_cmp_oratimestampltz(PG_FUNCTION_ARGS)
588613 PG_RETURN_INT32 (timestamp_cmp_internal (dt1 , dt2 ));
589614}
590615
591- /*****************************************************************************
592- * Hash index support procedure
593- *****************************************************************************/
616+ /**
617+ * Compute a hash value for an oradate value for use in hash indexes.
618+ *
619+ * @returns A Datum containing the hash of the 8-byte internal timestamp representation.
620+ */
594621Datum
595622oradate_hash (PG_FUNCTION_ARGS )
596623{
@@ -734,14 +761,16 @@ oradate_oratimestamptz(PG_FUNCTION_ARGS)
734761 PG_RETURN_TIMESTAMPTZ (timestamp2timestamptz (timestamp ));
735762}
736763
737- /* oradate_oratimestampltz()
738- * Convert oradate to oratimestampltz.
764+ /**
765+ * Convert an Oracle DATE value (oradate) to a timestamptz value.
766+ *
767+ * @param timestamp Internal Timestamp representing the Oracle DATE input.
768+ * @returns The equivalent TimestampTz representing the same absolute instant.
739769 */
740770Datum
741771oradate_oratimestampltz (PG_FUNCTION_ARGS )
742772{
743773 Timestamp timestamp = PG_GETARG_TIMESTAMP (0 );
744774
745775 PG_RETURN_TIMESTAMPTZ (timestamp2timestamptz (timestamp ));
746- }
747-
776+ }
0 commit comments