What should we do with a sentence like this: Working all day, he decided to skip the gym yesterday. Or this: Flying all night, he was so tired he went straight to bed when he got to the hotel. Both sentences begin with what is called a present participle, and therein lies the reason both statements are grammatically dissonant.
Depending upon your belief about the origin of language, a participle is either an ingenious invention or a marvelous discovery, but either way it poses a challenge to writers to stay consistent in references to time (another mystery for us to divine). The participle is defined as a verbal adjective, which means it is an adjective created from a verb. We know that a verb names an action and we know that an adjective describes a noun. If we fuse the two, we give ourselves a way to convert an action into a quality: he works all day becomes working all day; he flies all night becomes flying all night. The action of the verb, in other words, becomes a part of the subject, freeing us to create another clause to show what we regard as the real action of the sentence: he decided to skip the gym, or he was so tired.
But if a participle is created in part from a verb, it brings with it the notion of time, because verbs have tense. In a sentence like working all day, he decided to skip the gym yesterday, the question of when he worked arises. We can surmise, and no doubt be correct, that the day the subject worked was the same day he decided to skip the gym, but his working had to have occurred before making that fateful decision. And because a cause must precede its effect, the tense of the participle is incorrect. Instead of working all day, we should read having worked all day. And the same can be said for the second sentence we are examining. Because the subject flew all night, he was subsequently so tired that he went straight to bed. His flying must have preceded his nap, and so we should read having flown all night, he was so tired he went straight to bed.
Participles in English can form three tenses (present, past, and perfect), but it is the present participle that first concerns us here. This form of the participle is easy to identify because it always ends with the suffix –ing (though be forewarned that not every word ending in that suffix is a participle). The trick comes in understanding how time works in participles. If I write he works, the simple present tense of the verb tells the reader to conceive of the action in the present—the present according to the clock, meaning real or absolute time. Participial time, however, is relative, not absolute, which means a participle always ties itself to the time of the main verb. A present participle does not indicate actual time according to the clock, but a present contemporaneous with the time of the main verb. So to write working all day means that the subject was working at the very time he decided not to go to the gym yesterday. And that, as we have seen, was not logically the case.
Likewise the perfect participle, having worked all day. Perfect participles are also easy to recognize because they are always composed with the word having. The term perfect refers in grammar to a past or completed action, but once again the participial idea of past is not absolute but relative to the time of the main verb. So if it is true that the subject of our sentence worked before he decided not to go to the gym, or flew all night before he went straight to bed, then the participles conveying those prior actions must be written in the perfect tense: having worked and having flown, because the working and flying occurred before the already past tenses of their main verbs, decided and was. The perfect participle, therefore, represents time past to an already past tense.
The watchword, then, is that participle time is relative to the time of the main verb of a sentence: the present participle indicates time contemporaneous and the perfect participle indicates time prior. Such are the mysterious ways of time in language and in our mind.