AnsweredAssumed Answered

Pop-up expression

Question asked by whitloy on Mar 19, 2018
Latest reply on Mar 20, 2018 by xander_bakker

Hi-

I am using the labeling from this link for my street sweeping application and the date is incorrect

Create Map - My Government Services | ArcGIS for Local Government 

It is returning the same for routes with different sweep days. Example, sweep day for route 12 is Friday, but is returning a date of 3/25 and route 7 has a sweep day of Wednesday, but the expression is returning 3/25 as well.

 

Thanks!!

 

The code is below:

 

/*If the cleaning isn't available year-round 
specify the first and last day of the season that cleaning will occur*/
var openSeason = [[1,1],[12,31]]

var cleaningWeek = [];
var cleaningWeekFields = [$feature.WEEKONE, $feature.WEEKTWO,
                          $feature.WEEKTHREE, $feature.WEEKFOUR]
for (var k in cleaningWeekFields) {
    if (cleaningWeekFields[k] == 'Yes') {
        cleaningWeek[Count(cleaningWeek)] = k;
    }
}
if (Count(cleaningWeek)    == 0)
    return;
   
function getNextCleaningWeek(fromDate) {
    var firstSundayCurrentMonth = Date(Year(fromDate), Month(fromDate), 1);
    var firstWeekday = Weekday(firstSundayCurrentMonth);
    if (firstWeekday > 0)
        firstSundayCurrentMonth = DateAdd(firstSundayCurrentMonth, 7 - firstWeekday, 'days');
    for (var k in cleaningWeek) {
        var startCleaningWeek = DateAdd(firstSundayCurrentMonth, (cleaningWeek[k]*7), 'days');
        if (fromDate <= startCleaningWeek)
            return [startCleaningWeek, DateAdd(startCleaningWeek, 6, 'days')];
    }
   
    var firstSundayNextMonth = Date(Year(fromDate), Month(fromDate) + 1, 1);
    var firstWeekday = Weekday(firstSundayNextMonth);
    if (firstWeekday > 0)
        firstSundayNextMonth = DateAdd(firstSundayNextMonth, 7 - firstWeekday, 'days');
    var startCleaningWeek = DateAdd(firstSundayNextMonth, (7 * cleaningWeek[0]), 'days');
    return [startCleaningWeek, DateAdd(startCleaningWeek, 6, 'days')];
}
   
function validateSeasonCleaning(cleaningWeek) {
    var startSeasonMonth = openSeason[0][0]-1;
    var startSeasonDay = openSeason[0][1];
    var endSeasonMonth = openSeason[1][0]-1;
    var endSeasonDay = openSeason[1][1];
   
    if (Date(Year(cleaningWeek[1]), startSeasonMonth, startSeasonDay) > Date(Year(cleaningWeek[1]), endSeasonMonth, endSeasonDay)) {
        if (cleaningWeek[1] < Date(Year(cleaningWeek[1]), startSeasonMonth, startSeasonDay) && cleaningWeek[1] > Date(Year(cleaningWeek[1]) - 1, endSeasonMonth, endSeasonDay))
            cleaningWeek = getNextCleaningWeek(Date(Year(cleaningWeek[1]), startSeasonMonth, startSeasonDay))
    }
    else {
        if (cleaningWeek[1] < Date(Year(cleaningWeek[1]), startSeasonMonth, startSeasonDay))
            cleaningWeek = getNextCleaningWeek(Date(Year(cleaningWeek[1]), startSeasonMonth, startSeasonDay));
        else if (cleaningWeek[1] > Date(Year(cleaningWeek[1]), endSeasonMonth, endSeasonDay))
            cleaningWeek = getNextCleaningWeek(Date(Year(cleaningWeek[1]) + 1, startSeasonMonth, startSeasonDay));
    }
    return cleaningWeek;
}

var nextCleaning = getNextCleaningWeek(Today());
nextCleaning = validateSeasonCleaning(nextCleaning);
return Text(nextCleaning[0], 'MMMM D, YYYY');

Outcomes