Also, sometime those weird hours of opening till 4 a.m. is related to public transportation. In Tokyo public transportation does not run 24 hrs. Usually last train, subway, or bus is around 12 midnight to 1 a.m. Some stores do want to open till last train of the day to get business from those taking the last train. Those time when I ended up taking last train home I was surprised how packed the last train was. But that leaves employees no way to get home if the store close after the last train. Some business do decide to remain open till first train in the morning so that employees will have place to stay and same time able to get business from people taking the last train of the day.
I was at a small izakaya in Tokyo once which this small izakaya opened till 4 a.m. in the morning. I just asked the manager that if there was that much business late in the evening and early in the morning when trains and subways are not running. This is the answer the manager gave me and he told me that it is actually common practice among some small restaurants/izakaya/coffee shops/stores in Tokyo.