looks very similar to this: https://github.com/dimagi/dimagi-utils/blob/master/dimagi/utils/dates.py#L341