How to calculate days/portion to file state tax with two states?

I relocated from State A to State B in the first half of 2023 and I assume I need to file state taxes with both states. I have no idea how to count the number of days and how to calculate the portion of income for each state. I would really appreciate it if the experts in this forum could kindly have a look at my case and help me figure this out. 

 

I would divide my 2023 into four periods:

 

  1. I lived and worked in State A.
  2. I got a new job with a company in State B. For the first few weeks, I worked on site in State B and stayed in a hotel from Monday to Friday, but went back to State A for the weekends.
  3. For the next few weeks, I worked remotely from my home in State A for my new company (whose office is in State B).
  4. I relocated and worked on site in State B and lived in State B, without going back to State A.

I would assume my periods 1 and 4 are relatively simple but how do I count days during those periods? Should I count all days or just weekdays? How should I count days during my periods 2 and 3?

 

My period 4 is more than half a calendar year so I assume I should file as a resident for State B and a non-resident for State A?