Creating Calendar Dictionary

Sub Main;

Var

MB: IMetabase;

CrInfo: IMetabaseObjectCreateInfo;

Calendar: ICalendarDimension;

CalAttr: ICalendarDimAttribute;

Begin

MB := MetabaseClass.Active;

CrInfo := MB.CreateCreateInfo;

CrInfo.ClassID := MetabaseObjectClass.KE_CLASS_CLNDIM;

CrInfo.Id := "NewCalDim";

CrInfo.Name := "New calendar dictionary";

CrInfo.Parent := MB.Root;

Calendar := MB.CreateObject(CrInfo).Edit As ICalendarDimension;

//Calendar period

Calendar.StartYear := 1990;

Calendar.EndYear := 2010;

//Type of calendar; Years-Six Months-Quarters-Months-Weeks-Days.

Calendar.Hierarchy := 3;

//Levels

Calendar.IncludeDays := True; //Days

Calendar.IncludeWeek := True; //Weeks

Calendar.IncludeMonths := True; //Months

Calendar.IncludeYears := True; //Years

//Changing the last level name for day

Calendar.LastLevelNameAsDay := True;

//5-day week starting from Monday

Calendar.WeekLevel.RestDays := DayOfWeekSet.Saturday Or DayOfWeekSet.Sunday;

//Custom attribute

CalAttr := Calendar.Attributes.Add;

CalAttr.Name := "Date";

//Display format: January, 1, 1990. (Mon)

CalAttr.Expression(-1).AsString := "@[d MMMM yyyy]+"" y. (""+@[ddd]+"")""";

(Calendar As IMetabaseObject).Save;

End Sub Main;

After executing the example a calendar dictionary is created in the repository root. Dictionary period: 1990-2010. Dictionary hierarchy includes the following levels: Day, Week, Month, Year. A week has 5 days. Name of the last level is replaced with the day displayed in the 01.01.1990 format. A custom attribute is also created displaying date at all levels as January, 1, 1990. (Mon).

See also:

Examples