Actually, a quick look in the dictionary tells me that 近日 is exactly the same: it can mean both ‘in a few days’ time’ and ‘a few days ago’. Context determines everything。
Is there any pattern here? I keep getting these wrong
The first question that came to my mind when I read this is… in what way are you getting them wrong? Readings? Meanings? If we’re talking about meanings then… a lot of it is about common usage? Is there a pattern? Yes, I think so. Is it perfect and without exceptions? No. In essence
先=first/preceding something else and therefore most of the time ‘before’
昨=last/the preceding
来=come
近=close
How exactly those meanings get interpreted and extended depends entirely on common usage. 先月 is commonly used to mean ‘last month’, and so that stuck. On the other hand, 昨日 is the most common way of saying ‘yesterday’, which led 先日 to take on another meaning. Same thing with 先年 – 去年 is more common as ‘last year’. I guess the main takeaway from this is that the sort of ‘precedence’ implied by 先 is more expansive than that implied by 昨 or 去.
Now, before I go any further, simple rule about kanji and Japanese in general: what comes before modifies what comes after. If you keep that in mind, things should become much clearer. For example:
年次 - Annual
次 does mean ‘next’, but it can also mean ‘time’ as in ‘once, twice, thrice, four times…’. Hence, this phrase implies a sort of ‘time’/‘occurrence’ characteristic. What sort of ‘occurrence’? A ‘year-occurrence’. Thus, an annual occurrence. Once a year. 次年, at least in Japanese, would probably give us something like ‘next year’ or ‘this coming year’. (You can compare it with 次回 for anime episodes: ‘next time on…’)
来日 - Coming to Japan (?)
来週 - Next week
来月 - Next month
来年 - Next year
年来 - For some years
For 来日, it depends entirely on how you read 日, even if that won’t give you ‘tomorrow’ or ‘the next day’. (cf @Leebo’s comment) For all the rest, you’ll notice that 来 seems to be linked to quite a consistent pattern. Why is that? Well… usage, I guess? It helps that 来 means ‘to come’, so you very intuitively get ‘the coming…’. What happened to 来日(らいじつ)then? Again, well… it’s not the most common word. The two most common words are あした and あす, and both are written 明日, and both meaning tomorrow.
As for why 年来 means ‘for the past few years’… what goes before modifies what comes after. It helps if you’ve seen more of these 〜来 patterns, but they’re far more common in Chinese (which I speak) than in Japanese, so I guess it’s no surprise if you haven’t seen them. In any case, here’s one way of looking at it: it’s a sort of ‘coming’, but what kind? It’s characterised by ‘year(s)’, so it’s a ‘year coming’.
Unfortunately, that doesn’t make a ton of sense: why not ‘a yearly coming’ then? So… I’ll have to explain it using Chinese grammar. How I see it, personally, is that 年 indicates a sort of starting point or duration: ‘coming (down over the) year(s)/from some years ago’. I think the most intuitive, literal English translation would be something like ‘it’s been some years coming’. Not exactly the same thing, but similar because it indicates that something has been happening for a few years.
近日 - Soon (forward in time)
近年 - Recent years (backward in time - why?)
For the last two… purely a result of usage. For some reason, 近日 works both for going forward and backward in time, whereas 近年 is reserved for the past. You’d probably use something like 将来の数年間 if you wanted to specify ‘years’ as a unit of time for measuring the future. Perhaps it’s just harder to say that something will last for years when discussing the future, whereas it’s easy, in common conversation, to state that something has been happening for the past few years.