Creating Calendar Dictionary

Sub UserProc;
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;
    //Calendar type: Years-Half-years-Quarters-Months-Weeks-Days
    Calendar.Hierarchy := 3;
    //Levels
    Calendar.IncludeDays := True//Days
    Calendar.IncludeWeek := True//Weeks
    Calendar.IncludeMonths := True//Months
    Calendar.IncludeYears := True//Years
    //Replace name of the last level with day
    Calendar.LastLevelNameAsDay := True;
    // 5-day week from Monday
    Calendar.WeekLevel.RestDays := DayOfWeekSet.Saturday Or DayOfWeekSet.Sunday;
    //Custom attribute
    CalAttr := Calendar.Attributes.Add;
    CalAttr.Name := "Date";
    //Display format: January, 1st ,1990  (Mon)
    CalAttr.Expression(-1).AsString := "@[d MMMM yyyy]+""  (""+@[ddd]+"")""";
    (Calendar As IMetabaseObject).Save;
End Sub UserProc;

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