This happens due to gaps are in the data. When you check for gaps, you'll see that D1 data has usually many missing days due to holidays.

Holidays are not accounted for in tdm() and tom(), so the comparison tdm(0)==tom(0) will only work when no full days are missing, such as with M1 data of 24 hours traded assets. Otherwise you need to check the day of week for determining if you're at the end of the month.