This months birthdays

3
Hi guys, I was wondering how I could create a form with the upcoming birthdays of this month. I was thinking of creating an Xpath-constraint in which would be calculated what the current month and day are (in integers, with something like "parseInteger(formatDateTime($Employee/Birthday, 'mm'))" and "parseInteger(formatDateTime($Employee/Birthday, 'dd'))") and then to do the same thing with %CurrentDateTime% and then to compare these values. Problem is though that these functions cannot be used in Xpath constraints. I'd have to use variables and whatnot but I'm completely lost now. Please help me out :) Jelle
asked
4 answers
5

This month is a simple case in XPath: [month-from-dateTime($Employee/Birthday) = month-from-dateTime('[%CurrentDateTime%]')]

To be complete and for others, the complexity comes with this week's birthdays. Because you can't caculate with the week-from-datetime function. The reason there for is that a specific date does not fall every year in the same week. 8 july 2011 can have a other week number then 8 july 1967 for example. Same for the day-of-year-from-datetime function. Due to leap-year a date doesn't have each year the same day-of-year number.

We have coded some cases and here is the java function we use to build the xpath.

public static String getDatumTokenString(DynamischeDatumsToekomst dynamischeDatums, String field) 
{
    Calendar cal = Calendar.getInstance();

    //RUNTIME TOKENS 
    final String MONTH_LENGTH = "[%MonthLength%]";
    final String CURRENT_DATE_TIME = "[%CurrentDateTime%]";

    // voorbeelden: week van 29 december '10 -> 1228 (wordt 1227 in SQL), week van 6 jan '11 -> 104 (wordt 103)
    final String dezeWeekDeel1  = "day-from-dateTime('[%BeginOfCurrentWeek%]') + 1 + month-from-dateTime('[%BeginOfCurrentWeek%]') * 100";

    // voorbeelden: week van 29 december '10 -> 1235 (wordt 1234 in SQL), week van 6 jan '11 -> 111 (wordt 110)
    final String dezeWeekDeel2  = "day-from-dateTime('[%BeginOfCurrentWeek%] + [%WeekLength%]') + 1 + month-from-dateTime('[%EndOfCurrentWeek%]') * 100";

    // voorbeelden: week van 29 december '10 -> 97 (wordt 96 in SQL), week van 6 jan '11 -> 104 (wordt 103)
    final String dezeWeekDeel3  = "day-from-dateTime('[%BeginOfCurrentWeek%] + [%WeekLength%]') - 6 + month-from-dateTime('[%BeginOfCurrentWeek%] + [%WeekLength%]') * 100";

    // voorbeelden: week van 29 december '10 -> 104 (wordt 103 in SQL), week van 6 jan '11 -> 111 (wordt 110)
    final String dezeWeekDeel4 = "day-from-dateTime('[%BeginOfCurrentWeek%] + [%WeekLength%]') + 1 + month-from-dateTime('[%BeginOfCurrentWeek%] + [%WeekLength%]') * 100";

    // voorbeelden: week van 22 december '10 -> 1228 (wordt 1227 in SQL), week van 6 jan '11 -> 111 (wordt 110)
    final String volgendeWeekDeel1 = "day-from-dateTime('[%BeginOfCurrentWeek%] + [%WeekLength%]') + 1 + month-from-dateTime('[%BeginOfCurrentWeek%] + [%WeekLength%]') * 100 ";

    // voorbeelden: week van 22 december '10 -> 1235 (wordt 1234 in SQL), week van 6 jan '11 -> 118 (wordt 117)
    final String volgendeWeekDeel2 = "day-from-dateTime('[%BeginOfCurrentWeek%] + [%WeekLength%]') + 8 + month-from-dateTime('[%BeginOfCurrentWeek%] + [%WeekLength%]') * 100"; 

    // voorbeelden: week van 22 december '10 -> 97 (wordt 96 in SQL), week van 6 jan '11 -> 111 (wordt 110)
    final String volgendeWeekDeel3 = "day-from-dateTime('[%BeginOfCurrentWeek%] + 2 * [%WeekLength%]') - 6 + month-from-dateTime('[%BeginOfCurrentWeek%] + 2 * [%WeekLength%]') * 100";

    // voorbeelden: week van 22 december '10 -> 104 (wordt 103 in SQL), week van 6 jan '11 -> 118 (wordt 117)
    final String volgendeWeekDeel4 = "day-from-dateTime('[%BeginOfCurrentWeek%] + 2 * [%WeekLength%]') + 1 + month-from-dateTime('[%BeginOfCurrentWeek%] + 2 * [%WeekLength%]') * 100";

    String returnValue = "";

    switch (dynamischeDatums)
    {

        case Deze_week: 
            // Dit kan niet op dezelfde manier als deze_maand omdat de dag in andere jaren niet persé in dezelfde week valt. 

            returnValue = "[(day-from-dateTime(" + field + ") + month-from-dateTime(" + field + ") * 100 >= " + dezeWeekDeel1 + "  and " +  
                        "day-from-dateTime(" + field + ") + month-from-dateTime(" + field + ") * 100 < "+ dezeWeekDeel2+ ")";

            if(cal.get(Calendar.DAY_OF_YEAR)>= 359){
                returnValue += " or (day-from-dateTime(" + field + ") + month-from-dateTime(" + field + ") * 100 >= "+dezeWeekDeel3+" and " +
                "day-from-dateTime("+ field +") + month-from-dateTime(" + field + ") * 100 < "+dezeWeekDeel4+")]";
            }
            else returnValue += "]";

            return  returnValue;

        case Volgende_week: 
            returnValue = "[(day-from-dateTime(" + field + ") + month-from-dateTime(" + field + ") * 100 >= "+volgendeWeekDeel1+" and " +  
            "day-from-dateTime(" + field + ") + month-from-dateTime(" + field + ") * 100 < "+volgendeWeekDeel2+")";

            if(cal.get(Calendar.DAY_OF_YEAR)>= 352 && cal.get(Calendar.DAY_OF_YEAR) < 359){
                returnValue += " or (day-from-dateTime(" + field + ") + month-from-dateTime(" + field + ") * 100 >= "+volgendeWeekDeel3+" and " +
                "day-from-dateTime("+ field +") + month-from-dateTime(" + field + ") * 100 < "+volgendeWeekDeel4+")]";
            }
            else returnValue += "]";

            return  returnValue;

        case Deze_maand: 
            return "[month-from-dateTime(" + field + ") = month-from-dateTime('" + CURRENT_DATE_TIME + "')]"; 

        case Volgende_maand: 
            return "[month-from-dateTime(" + field + ") = month-from-dateTime('" + CURRENT_DATE_TIME + "') + 1]"; 

        default: return "";
    }
}
answered
1

While not the best solution at all times, we use a calendar module for some of our projects. It basically models days, weeks, months and years as objects. When you determine a persons birthday you can link it to that day object. Then it would be easy to determine the upcomming birthdays. This however, does require a lot of modelling if you are only gonna use it once.

answered
0

Try this:

[$Employee/Birthday >= '[%BeginOfCurrentMonth%]' and $Employee/Birthday <= '[%EndOfCurrentMonth%]']

Edit:

And if you want the birthdays upcoming in the next 30/31 days, you can use '[%CurrentDateTime%] + [%MonthLength%]' instead of BeginCurrentMonth.

Edit2: As Herbert pointed out, I forgot the years. You could rewrite it with month-from-dateTime as Herbert mentioned and get all the birthdays that happen in that specific month. (Apply this to the attribute and CurrentDateTime and compare)

answered
0

You could use Robert's suggestion. But if you need to compare a date range in your xpath in general, keep this in mind:

Basically you need to create 2 datetime variables, begin and end. In your xpath you can do something like this:

$Entity/birthday > $begin and $Entity/birthday < $end

You can create the begin and end variable with using [%CurrentDateTime%] and the addDays function.

answered