James Programming in Mosaic Nov 29, 2023, 5:02 PM Dec 1, 2023, 10:47 AM

Hello!
Is there a built-in function in mosaic that calculates the date of the first Sunday of Advent?
Regards,
Balázs Marozs

Answers 3

Luboš Urban Nov 29, 2023, 6:25 PM

Hello Marosz,

unfortunately, there is not such function in Mosaic libraries. I can try to figure out how to count off the four weeks from Christmas Day.

M.B. Dec 1, 2023, 10:33 AM

Function for estamination of the first advent by the year may look like this (TimeLib is required for proper function):

 


FUNCTION GetFirstAdventSundayDate : DATE
(*
  Get date of the first advent sunday for years 2000 - 2099
*)
  VAR_INPUT
    year : UINT;
  END_VAR
  VAR_IN_OUT
  END_VAR
  VAR
    tdt : TTecoDateTime;
    idt2 : DT;
  END_VAR
  VAR_TEMP
  END_VAR

  IF year < 2000 OR year > 2099 THEN
    year := YEAR_OF_DATE(GetDate());
  END_IF;

  tdt.day := 27;
  tdt.month := 11;
  tdt.year := UINT_TO_USINT(year-2000);
  
  idt2 := TecoDT_TO_DT(Teco_DT := tdt);
  tdt := DT_TO_TecoDT(IEC_DT := idt2);
  GetFirstAdventSundayDate := LREAL_TO_DATE(DATE_AND_TIME_TO_LREAL(idt2) + USINT_TO_LREAL(7 - tdt.dayOfWeek)*86400.0);

END_FUNCTION

 

James Dec 1, 2023, 10:47 AM

Thank you for your time!
I made this program.
Unfortunately, this only indicates that day
 

VAR
 christmas_number        : UINT := 359;
 today_number            : UINT;
 Days_to_christmas       : UINT;
 today                   : UINT; //hét napjai
 future_day_of_week      : UINT; //hét napjai
 ADVENT                  : BOOL;
 end_var



 today_number := DAY_OF_YEAR(in :=GetDate());
 Days_to_christmas := (christmas_number - today_number);
 today := usint_to_uint(System_S.COUNTER_DAYS_OF_WEEK);
 future_day_of_week := (Days_to_christmas + (today - 1)) / 7;
 If future_day_of_week = 4 AND today = 7 Then
    ADVENT := True;
 Else
    ADVENT := False;
 End_if;
 
END_PROGRAM

Your answer

You have to be signed-in for asking a question. Continue after sign-in.