The day that you purchase shares begins the count toward long term. In your example, the first purchase is more than a year and receives LTCG status and the second purchase is less than a year and receives STCG status.
When you decide to sell a portion of your positions, there are several choices.
FIFO stands for first in, first out (you sell the shares bought first). This is the default position for the IRS. IOW, when you sell some shares, unless you specify otherwise, the Internal Revenue Service assumes that the assets that you sell first are also the one's that you bought first.
LIFO stands for last in, first out (you sell shares that you bought most recently)
With the Average Cost method, you add up the total value of all of your shares and divide by the number of shares that you own. This results in the same cost basis for all shares and when you sell shares, the IRS assumes that you sell the shares that you have held longest first. AFAIC, this method is the most complicated and is the most prone for user error. I believe that this is only applicable to mutual funds and certain DRIPs.
You can designate to your broker which shares are to be sold.
Here's an excerpt from a Zacks article that discusses this.
Here's a warning from another Zacks article:
"Warning: If you plan to use any method besides FIFO, including LIFO, you must specifically direct your broker as to which shares to sell so that your taxes end up the way you want. According to Internal Revenue Service Publication 550, the burden is on you to prove that you informed your broker of which shares you wanted sold and that your broker followed your requests. If you can't prove that, you're treated as having sold your oldest shares first."