Select to view content in your preferred language

Pop-up expression

1041
10
03-19-2018 04:24 PM
WhitneyLoy
Regular Contributor

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 == '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*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');
0 Kudos
10 Replies
XanderBakker
Esri Esteemed Contributor

Thanks for sharing KEkenes-esristaff . I have blogged about several implementations using Arcade and will see if I can pass some of them to the GitHub repository. 

0 Kudos