Great question! Absolutely, it's totally acceptable to ask someone how long they will be using the machine. I can't imagine anyone in our gym ever being offended by that. I would also add that it's perfectly fine to ask if you can work in with them as well.
However, there are some caveats. For example, if it's the leg press and they have 10 plates a side loaded on the machine and you only need one plate, it would be considered rude to ask to work in. In this case, I would just kindly ask how many sets they have left and if you can use the machine when they are done. If it's something with pin and stack loaded weights, by all means, working in between their sets is totally acceptable and even recommended.
For the sake of keeping this answer short, I'm going to make some notes after I post this question with a list of good gym etiquette. If any members want to chime in and add to my list, please feel free.
Gym Etiquette Guide
Good Gym Etiquette
Bad Gym Etiquette