Следующий код преобразует свойства расширенного типа данных даты в целочисленные параметры, пригодные для date2str().
Первая рекурсивная процедура загружает свойства расширенного типа:
PHP код:
private void loadDateFormatProperties(ExtendedTypeId _typeId)
{
#Properties
str property, properties;
SysDictType sysDictType;
#define.Auto("Auto")
;
sysDictType = new SysDictType(_typeId);
if (! sysDictType || isSysId(sysDictType.id()))
return;
properties = sysDictType.treeNode().AOTgetProperties();
property = findProperty(properties, #PropertyDateformat);
propertyDateFormat = property != #Auto ? property : "";
property = findProperty(properties, #PropertyDateSeparator);
propertyDateSeparator = property != #Auto ? property : "";
property = findProperty(properties, #PropertyDateYear);
propertyDateYear = property != #Auto ? property : "";
property = findProperty(properties, #PropertyDateMonth);
propertyDateMonth = property != #Auto ? property : "";
property = findProperty(properties, #PropertyDateDay);
propertyDateDay = property != #Auto ? property : "";
if ((! propertyDateFormat ||
! propertyDateSeparator ||
! propertyDateYear ||
! propertyDateMonth ||
! propertyDateDay) &&
sysDictType.extend())
{
this.loadDateFormatProperties(sysDictType.extend());
}
}
Вторая - анализирует их и сохраняет собственно указанные выше параметры:
PHP код:
protected void loadDateFormat()
{
int i, digit;
str defSeparators;
if (loaded)
return;
propertyDateFormat = "";
propertyDateSeparator = "";
propertyDateYear = "";
propertyDateMonth = "";
propertyDateDay = "";
this.loadDateFormatProperties(this.extTypeId());
// DATE FORMAT
intDateSequence = 0;
if (propertyDateFormat)
{
// for example "YMD" -> 321
for (i = 1; i <= 3; i++)
{
switch (substr(propertyDateFormat, 4-i, 1))
{
case 'D' : digit = 1; break;
case 'M' : digit = 2; break;
case 'Y' : digit = 3; break;
}
intDateSequence += exp10(i-1) * digit;
}
}
else // 'Auto' -> Usually "DMY" -> 123
{
intDateSequence = SF_PropType_AtomDate::defSequence();
}
// DAY DIGITS
switch (propertyDateDay)
{
case "Always two digits":
intDateDay = 2;
break;
case "One or two digits":
intDateDay = 1;
break;
default:
intDateDay = SF_PropType_AtomDate::defDayDigits();
}
// SEPARATORS
intDate1Separator = 0;
intDate2Separator = 0;
defSeparators = SF_PropType_AtomDate::defSeparators();
if (! propertyDateSeparator)
{
propertyDateSeparator = defSeparators;
}
propertyDateSeparator = strReplace(propertyDateSeparator, "(none)", 'N');
propertyDateSeparator = strReplace(propertyDateSeparator, "(space)", 'S');
for (i = 1; i <= 2; i++)
{
switch (substr(propertyDateSeparator, i, 1))
{
case 'S' : digit = 1; break;
case '.' : digit = 2; break;
case '-' : digit = 3; break;
case '/' : digit = 4; break;
default :
propertyDateSeparator = strPoke(propertyDateSeparator, substr(defSeparators, i, 1), i);
i--;
continue;
}
if (i == 1)
{
intDate1Separator = digit;
}
if (i == 2)
{
intDate2Separator = digit;
}
}
// MONTH DIGITS
switch (propertyDateMonth)
{
case "Always two digits":
intDateMonth = 2;
break;
case "One or two digits":
intDateMonth = 1;
break;
default:
intDateMonth = SF_PropType_AtomDate::defMonthDigits();
}
// YEAR DIGITS
switch (propertyDateYear)
{
case "Two digits":
intDateYear = 2;
break;
case "Four digits":
intDateYear = 4;
break;
default:
intDateYear = SF_PropType_AtomDate::defYearDigits();
}
loaded = true;
}