Calculating the estimated print time of an already sliced file
First of all, there are some nice open source analyzers written in JavaScript that you can use online, or read the source to, at https://www.gcodeanalyser.com/ and http://gcode.ws/. Their predictions don't fully match actual printer firmware, but they do a reasonably close job, and reading them would be informative.

Basically, the story behind acceleration and jerk is that you can't change the velocity (speed or direction) of the print head instantaneously. It takes time to speed up and slow down. Acceleration is the max rate at which the velocity of the print head can change. Jerk is something of a misnomer/hack, and is the max fake-instantaneous change in velocity allowed at the junction of two segments/curves. The point of jerk is to avoid choppy motion when moving along a curve made up of many segments by accelerating/decelerating at each tiny corner. Note that there are two sets of settings for both acceleration and jerk:


a maximum absolute value (3D vector length) that frequently changed as part of the gcode in order to use different acceleration profiles for print moves vs travel moves, walls vs infill, etc.
per-axis absolute values (standard 1D absolute value) for the limitations of the machine, that are usually set in the printer's settings or the start gcode profile for your printer and never changed.


Movement is constrained to always respect both sets of settings.

Printer firmware uses acceleration and jerk settings along with lookahead at upcoming motion commands to decide how to actually operate the motors. When it starts a motion, it has to accelerate up to the configured max velocity within the acceleration constraints. It also has to start slowing back down midway through unless it knows the next motion is going to continue in the exact same direction; how much it has to slow down depends on the difference in the vectors of motion. If the next motion is going to be in approximately the same direction, it may be able to avoid slowing down by using the jerk allowance to make an "instantaneous" change of velocity at the corner. Only if you have long (relative to speed) linear or approximately linear motions will you ever actually reach the requested speed.

So, to estimate print time, you need to model this. Keep track of print head velocity while processing/simulating the gcode, and for each motion command, compute velocity as a function of time using the acceleration limits (accelerating at the max rate they allow). You also need to figure out the final velocity you want to end the motion with in order to be able to start the next motion command, and a point to start decelerating if necessary to reach that.