IRS form 2555 qualifies you for the IRS Foreign Earned Income Exclusion(FEIE), and is a simple form to fill out with the rest of your taxes, takes 5-20 minutes depending on how many countries you lived in that year.
IRS instructions for form 2555.
This is the official language of the IRS form 2555 physical presence test:
“You meet the physical presence test if you are physically present in a foreign country or countries 330 full days during any period of 12 consecutive months including some part of the year at issue. The 330 qualifying days do not have to be consecutive.”
Plainly, it doesn’t matter if you were absent from the United States between January 1st and December 31st to qualify, it only matters that you were not present in the United States for 330 of 365 consecutive days that include, in some part, the current tax year you are applying the exemption to.
You could have been in the US until april, and then outside the US from May until the following april, and that’s fine to claim the FEIE and exclude a variable amount of your earned income tax as determined each year by the IRS (currently at $130,000 annually).
By tax year(Jan. 1 - Dec. 31) you were only out of the country for 270 days, but out of 365 calendar days, you were not physically present in the US for 330+ days from May to April, and so you pass the physical presence test, which qualifies you for the Foreign Earned Income Exclusion.
It can be a US or non-US company that employs and pays you, you just have to be physically outside the US.
This IRS exemption is for earned income, so self-employment tax, capital gains, dividends and other excluded "unearned" incomes can still be taxed.
Ask any questions below, I'm happy to answer.