(CNN) -- The European Union Court of Justice has ruled that working fathers in Spain have the same right to breastfeeding leave as do moms.

Thursday's ruling grants Spanish dads the same rights as the mother of their child to leave work up to twice a day for a total of an hour or to shorten their workday by 30 minutes for the first nine months of the baby's life.

The court called the law "an unjustified discrimination on grounds of sex" that fathers weren't granted breastfeeding leave in the same instances as women were.

The statute, challenged by Pedro Manuel Roca Alvarez, didn't allow dads to take the same leave afforded to women if the mother of their children didn't work or were self-employed.

The law was "liable to perpetuate a traditional distribution of the roles of men and women by keeping men in a role subsidiary to that of women in relation to the exercise of their parental duties."