“while they were there.” The Greek is more literally, “in their being there.” This is well translated as, “while they were there,” which is the translation in most English versions. Note that this verse makes it clear that they had not just arrived that day. The specific Greek phrase occurs in three other verses besides this one, and it does not refer to just arriving or just starting something—it refers to being “in” the middle of something. In Luke 5:12 Jesus was visiting a town when a man came to him to be healed. He had not just arrived at the town, he was “in” it. In Luke 9:8 the disciples came to him “while” he was praying. He had not just started, he was in the midst of prayer. Similarly, in Luke 11:1 Jesus was “in” prayer, and when he had finished a disciple asked a question.
The point is that Joseph and Mary had not just arrived in Bethlehem, as the traditional Christmas story teaches. They had been in Bethlehem a while, but the Bible never says exactly how long.