The Moon's orbital period, measured by the stars (“sidereal period") is 27.321662 days. However, the monthly cycle of the Moon --- thin crescent to half-moon, to full and back to crescent --- takes 29.530589 days, because it depends on the position of the Sun in the sky, and that position changes appreciably in the course of each orbit. The different shapes of the Moon represent different angles of illumination, and the appearance of the Moon in the night sky gives a fair idea of where the Sun would be (e. g. the Moon observed in the east before sunrise appears illuminated from below). The duration of the Moon's cycle (“synodic period") gave rise to the division of time known as month.
Many ancient calendars were based on the month. The most successful of these is the “Metonic" calendar, named after the Greek Meton, who noted that adding 7 months in the course of 19 years kept the calendar almost exactly in step with the seasons. That would make the length of the average year (12 + 7/19) months, and with a calculator you can easily find its value as
pretty close to the full value 365.2422. The Metonic calendar is thus more accurate than the Julian one, though less so than the Gregorian. It is still used by Jews, on whose calendar each month begins at or near the new moon, when the Moon's position in the sky is nearest to the Sun's. The traditional Chinese calendar also uses of a formula like Meton's, which was probably invented by the ancient Babylonians. For more about the ancient Babylonian calendar see en.Wikipedia.org/wiki/Babylonian_calendar.