Time-dependent CO depletion during the formation of protoplanetary disks