EDMONTON -- An Alberta judge has ruled that a war crimes sentence for former Guantanamo Bay prisoner Omar Khadr has expired.

An eight-year sentence imposed in 2010 would have ended last October had Khadr remained in custody.

But the clock stopped ticking when a judge freed him on bail in 2015 pending Khadr's appeal of his military conviction in the United States.

Chief Justice Mary Moreau says the Youth Criminal Justice Act gives judges flexibility to consider bail conditions as part of a sentence.

She told an Edmonton court Monday that, with that in mind, she ruled Khadr has served his time.

The Supreme Court of Canada had already said the punishment handed Khadr for alleged acts committed in Afghanistan when he was 15 years old was to be a youth sentence.

Khadr's lawyer Nathan Whitling had argued earlier this year that Khadr had served more than seven years in custody and on bail.

The Crown had argued Khadr should serve the remainder of his sentence in the community.

Whitling said the appeal of the sentence in the U.S. hadn't moved forward at all and it would be unfair to use that against his client.

Whitling also argued that the military commission that sentenced Khadr has been widely discredited by legal experts.

Khadr spent years in U.S. detention at Guantanamo Bay after he was captured and accused of tossing a grenade that killed special forces soldier Christopher Speer at a militant compound in Afghanistan in 2001.

Since his release on bail, Khadr has lived in Edmonton and Red Deer, Alta., without incident. The court had eased some of his initial bail conditions, but several remained in place.

Khadr could not have access to a Canadian passport and was banned from unsupervised communication with his sister, who lives in the former Soviet republic of Georgia. He also had to notify his bail supervisor before leaving Alberta.

Moreau said all the conditions are lifted.

Khadr's case has ignited divisive debate among Canadians over terrorism, human rights and the rule of law since it was revealed in 2017 that the federal government settled a lawsuit filed by him for a reported $10.5 million.

The payout followed a 2010 ruling by Canada's Supreme Court that Khadr's charter rights were violated at Guantanamo and that Canadian officials contributed to that violation.