The events of this chapter must take place between the time Joseph is sold to the Midianites, aged 17 (Genesis 37:2), and the time when Judah goes down to Egypt with his brethren to buy grain. Joseph stands before Pharoah to interpret his dream when he is 30 (Genesis 41:46), and it is after seven years of plenty and two years of famine that the brothers first come down, so that Joseph is then 39 years old. This gives twenty-two years. During that time Judah moves away from home – soon after Joseph is sold – takes a wife, has three sons and chooses Tamar as wife for his oldest son, Er. When Er dies, Onan, maybe a year younger, is given to Tamar. When he too dies, the youngest son Shelah is promised to her but is too young for her to marry immediately. Perhaps he is one or two years younger. He reaches a marriageable age, but is not given to Tamar, and the terrible events concerning Judah take place. If we give a year for Judah to choose a wife and for his first son to be born, 16 or 17 years till he marries, another year for Onan to be old enough to marry, another one or two years for Shelah to reach marriageable age, then, although events are compressed, there is enough time for all this to take place.