Let's establish some notation:

  • The star is labelled $S$, the giant planet is $P$ and the moon is $M$.

  • The diameter of the star is $dS$, the diameter of the planet is $dP$ and the diameter of the moon is $d_M$.

  • The radius of the orbit of the planet is $rP$ and the radius of the orbit of the moon is $rM$.

  • At a distance equal to the radius $rM$ of the orbit of the moon $M$, the planet $P$ casts a shadow (which astronomers like to call the _umbra , using the Latin word for shadow) of diameter $d_U$.

See the following diagram showing the position of the star $S$, the planet $P$ and the moon $M$ when the totality phase of the eclipse begins for an observer sitting on the surface of the moon; we consider that the planet and the moon orbit in the plane of the picture, and we are looking at them from the north celestial pole.

The eclipse begins for an observer

The position of the three bodies when the totality phase of the eclipse begins for an observer. $S$ is the star with diameter $dS$. $P$ is the giant planet with diameter $dP$ and revolving around the star on an orbit with radius $rP$. $M$ is the moon with diameter $dM$ revolving around the giant planet on an orbit with radius $rM$. $dU$ is the diameter of the shadow ("umbra") of the giant planet at a distance equal to the radius $rM$ of the orbit of the moon $M$. Own work, available on Flickr under the CC BY 2.0 license. The diagram is absolutely not to scale._

We want to compute $dU$ given $dS$, $dP$, $rP$ and $rM$. (Why do we want to compute $dU$? Because we want to find out how much time the moon $M$ will take to move across the shadow.)

Notes

  1. The following calculations are not exact, but rather decent approximations good enough for a work of fiction. Exact calculations would take more time than I have available.

  2. The calculation refers to the totality phase of the eclipse, from the moment the sun is completely covered by the giant planet to the moment the first sliver of sunlight becomes visible.

From triangle similarity we have

$$\frac {rM}{rP} = \frac {dP - dU}{dS - dP}$$

which means that

$$dU = dP - \frac {rM}{rP} (dS - dP)$$

Plugging in the numbers

$d_S$ = 1,391,400 km (diameter of the Sun)

$d_P$ = 142,984 km (diameter of Jupiter)

$r_P$ = 149,597,870 km (1 astronomical unit)

$r_M$ = 4,000,000 km (given)

we find that

$$d_U = 142{,}984 - \frac {4{,}000{,}000}{149{,}597{,}870} (1{,}391{,}400 - 142{,}984) \approx 109{,}600 \text{ km}$$

The moon travels 2 $\pi$ × 4,000,000 kilometers in 42 days, or 598,399 km per day. The 109,600 km wide umbra will then be traversed in 109,600 / 598,399 = 0.183 days, or 4 hours 24 minutes.

During this time the moon has rotated a bit, about 60 degrees, so that the observer is still in the shadow -- the moon must move on its orbit a distance of about two thirds of its radius to bring the observer into the light. Assuming that the moon has the same radius as the Earth, 6,400 km, this will take about 4,000 / 598,399 days or about 10 minutes.

So the grand total is 4 hours and 34 minutes of total eclipse.

P.S. What about the total duration from the moment the planet touches the sun to the moment the entire sun is again visible? Given that the radius of the orbit of the moon is much smaller than the radius of the orbit of the planet, the diameter of the penumbra is only a little larger than the diameter of the planet, or let's say some 160,000 km. The moon will traverse the penumbra (and the umbra) in about 6 hours 50 minutes. What this means that if the eclipse (partial + total) begins at noon chances are it will end after sunset...

Note that this post-scriptum is even more approximative than the calculation for the totality phase, but still good enough for fiction.