FND Date
FND Date
FND_DATE as
-- $Header: AFDDATEB.pls 120.7.12020000.2 2015/02/11 17:32:45 rarmaly ship $
--
-- PUBLIC
--
-- Initialization routines
-- Assign the output masks - for now we'll derive them from the user mask.
-- Strip off any FX or FM in the mask. This wouldn't actually affect
-- the output, but we use this mask as the error mask as well.
FND_DATE.output_mask := REPLACE(REPLACE(FND_DATE.user_mask,'FM'),'FX');
FND_DATE.outputDT_mask := REPLACE(REPLACE(FND_DATE.userDT_mask,'FM'),'FX');
FND_DATE.user_calendar := upper(p_user_calendar);
if not (FND_DATE.user_calendar = 'GREGORIAN'
or FND_DATE.user_calendar = 'THAI BUDDHA'
or FND_DATE.user_calendar = 'ARABIC HIJRAH'
or FND_DATE.user_calendar = 'ENGLISH HIJRAH') then
FND_DATE.user_calendar := 'GREGORIAN';
end if;
--
-- Canonical functions
--
function canonical_to_date(canonical varchar2) return date is
dateval date;
new_canonical varchar2(30);
begin
new_canonical := canonical;
dateval := to_date(new_canonical, canonical_DT_mask);
return dateval;
end canonical_to_date;
--
-- Date/DisplayDate functions - covers on the now obsolete Date/CharDate
-- functions. These functions are used to convert a date to and from
-- the display format.
--
-- TZ*
function displayDT_to_date(charDT varchar2) return date is
begin
return displayDT_to_date(charDT, fnd_date.calendar_aware_default);
end displayDT_to_date;
-- TZ*
function date_to_displayDT(dateval date) return varchar2 is
begin
return date_to_displayDT(dateval, fnd_date.calendar_aware_default);
end date_to_displayDT;
-- Date/CharDate functions
-- TZ*
function charDT_to_date(charDT varchar2) return date is
begin
return charDT_to_date(chardt, fnd_date.calendar_aware_default);
end charDT_to_date;
-- TZ*
function date_to_charDT(dateval date) return varchar2 is
begin
return date_to_charDT(dateval, fnd_date.calendar_aware_default);
end date_to_charDT;
-- *TZ
--
-- Now try 'NUMERIC DATE LANGUAGE'
--
BEGIN
RETURN(To_date(p_string, p_mask,
'NLS_DATE_LANGUAGE = ''NUMERIC DATE LANGUAGE'''));
EXCEPTION
WHEN OTHERS THEN
NULL;
END;
--
-- For backward compatibility try 'ARABIC'.
-- 'ARABIC' uses numeric month names.
--
BEGIN
RETURN(To_date(p_string, p_mask,
'NLS_DATE_LANGUAGE = ''ARABIC'''));
EXCEPTION
WHEN OTHERS THEN
NULL;
END;
--
-- Now try currently installed languages.
--
DECLARE
--
-- Base language should come first.
--
CURSOR lang_cur IS
SELECT nls_language
FROM fnd_languages
WHERE installed_flag IN ('B','I')
ORDER BY installed_flag, nls_language;
BEGIN
FOR lang_rec IN lang_cur LOOP
BEGIN
RETURN(To_date(p_string, p_mask,
'NLS_DATE_LANGUAGE = ''' ||
lang_rec.nls_language || ''''));
EXCEPTION
WHEN OTHERS THEN
NULL;
END;
END LOOP;
EXCEPTION
WHEN OTHERS THEN
NULL;
END;
--
-- Now it is time to return NULL.
--
RETURN(NULL);
EXCEPTION
WHEN OTHERS THEN
--
-- This is Top Level Exception.
--
RETURN(NULL);
END string_to_date;
FUNCTION string_to_canonical(p_string IN VARCHAR2,
p_mask IN VARCHAR2)
RETURN VARCHAR2
IS
BEGIN
RETURN(To_char(string_to_date(p_string, p_mask),
fnd_date.canonical_dt_mask));
EXCEPTION
WHEN OTHERS THEN
RETURN(NULL);
END string_to_canonical;
-- use 'set serverout on;' to see the output from this test program
-- NOTE: If this test program is run twice in a row you get an ORA-600. This
-- is logged against PL/SQL as 771171
procedure test is
my_date date := SYSDATE;
my_char varchar2(20) := '01/01/2000 21:20:20';
begin
null;
/*
--commented out to avoid aru check constraints.
-- tz*
DBMS_OUTPUT.PUT_LINE('About to call timezone initialize');
if fnd_timezones.TIMEZONES_ENABLED = 'Y' then
fnd_date_tz.init_timezones_for_fnd_date;
else
DBMS_OUTPUT.PUT_LINE('Timezones are not enabled');
end if;
date_to_displayDT(fnd_date.displaydate_to_date('02/01/2
000')));
DBMS_OUTPUT.PUT_LINE('Valid DT is '||
date_to_displayDT(fnd_date.displayDT_to_date(my_char)));
DBMS_OUTPUT.PUT_LINE('Canon date is '||fnd_date.date_to_canonical(sysdate));
DBMS_OUTPUT.PUT_LINE('and back is
'||fnd_date.date_to_displayDT(fnd_date.canonical_to_date('2001/03/12
14:22:22')));
select date_to_displayDT(sysdate+5)
into my_char
from dual;
select date_to_canonical(sysdate+5)
into my_char
from dual;
end;
-- tz*
function date_to_displayDT(dateval date,new_client_tz_code varchar2) return
varchar2 is
begin
end date_to_displayDT;
t_dateval := dateval;
if fnd_date.timezones_enabled then
end date_to_displayDT;
end displayDT_to_date;
if fnd_date.timezones_enabled then
return dateval;
end displayDT_to_date;
-- *tz
function calendar_awareness_profile(p_application_id number) return varchar2
is
begin
return nvl(fnd_profile.value_specific(name =>
'FND_DATE_API_CALENDAR_AWARENESS_DEFAULT',
application_id => p_application_id),
'0');
end calendar_awareness_profile;
buffer := elems(ELEM_YEAR)||'-'||elems(ELEM_MONTH)||'-'||elems(ELEM_DAY)
||'T'||elems(ELEM_HOUR)||':'||elems(ELEM_MIN)||':'||elems(ELEM_SEC);
if elems(ELEM_OFFSET) = OFFSET_NOT_SET or
fnd_timezones.get_server_timezone_code is null or
fnd_timezones.get_server_timezone_code = '' then
select to_date(buffer, iso8601_mask_localtime) into retdate from dual;
else
select to_timestamp_tz(buffer||decode(elems(ELEM_OFFSET), -1, '-', 1, '+',
'+')||elems(ELEM_OFFSET_HOUR)||':'||elems(ELEM_OFFSET_MIN),
iso8601_mask_localtime||'TZH:TZM') at time zone
fnd_timezones.get_server_timezone_code into retdate from dual;
end if;
return retdate;
end iso8601_to_date;
BEGIN
-- Assign the output masks - for now we'll derive them from the user mask.
-- Strip off any FX or FM in the mask. This wouldn't actually affect
-- the output, but we use this mask as the error mask as well.
FND_DATE.output_mask := REPLACE(REPLACE(FND_DATE.user_mask,'FM'),'FX');
FND_DATE.outputDT_mask := REPLACE(REPLACE(FND_DATE.userDT_mask,'FM'),'FX');
-- TZ*
fnd_date.timezones_enabled := false;
-- *TZ
-- For non-Gregorian calendar support.
fnd_date.user_calendar := 'GREGORIAN';
fnd_date.is_non_gregorian := false;
end FND_DATE;
/