The phrases for many days and in a cocoon are preposition phrases. They consist of the prepositions for and in and their respective noun phrase complements many days and a cocoon. They are functioning as Adjuncts (read "adverbials").
Preposition phrase Adjuncts like these are not Complements of the verb phrase. Rather they modify the verb phrase itself. For this reason they are not tightly integrated with the rest of the phrase and can often appear in any order:
- She plays football [with her friends] [in the park].
- She plays football [in the park] [with her friends].
Occasionally there may be information packaging reasons for putting one preposition phrase Adjunct first and another last. However, this has nothing to do with the grammar.
Both of the Original Poster's sentences are perfectly grammatical. In these examples the prepositional phrases are modifying the verb phrase rest.