Every calendar in the world solves the same arithmetic problem, and there are only three solutions. A lunation is about 29.53 days and a tropical year about 365.2422 days, and the second is not a whole multiple of the first. A calendar can therefore follow the Moon and let its year drift against the sun, follow the sun and let its months lose contact with the Moon, or follow both and insert an extra month at intervals to keep them together.
The Chinese calendar takes the third path, and it is the most astronomically demanding of the major lunisolar systems because it fixes both the month and the intercalation by true positions rather than by a cycle. A month begins on the day of the astronomical new moon, so months are 29 or 30 days as the Moon actually runs, and the eleventh month is defined as the one containing the winter solstice.
Intercalation follows from the twenty-four solar terms rather than from a nineteen-year rule. A lunar month that contains none of the twelve major terms is declared a leap month and takes the number of the month before it, so a year can have thirteen months without any fixed schedule saying which years those are.
Running alongside all of this is the sexagenary cycle of ten stems and twelve branches, which names years, months, days and double hours and is independent of every astronomical quantity. The day count in particular has run without interruption since the Shang oracle bones, which makes it the longest continuously operating day count known and a check on Chinese historical chronology in its own right.