blob: 64ef3b7154342893f9d50543d718ff62302b2b99 [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2018 Agence spatiale canadienne / Canadian Space Agency
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Pierre Allard,
* Regent L'Archeveque,
* Olivier L. Larouche - initial API and implementation
* SPDX-License-Identifier: EPL-1.0
*
*******************************************************************************/
package org.eclipse.apogy.common.emf.impl;
import org.eclipse.apogy.common.emf.ApogyCommonEMFFactory;
import org.eclipse.apogy.common.emf.Duration;
import org.eclipse.apogy.common.emf.Timed;
public class DurationCustomImpl extends DurationImpl {
private static long MILLISEC_PER_SECOND = 1000;
private static long MILLISEC_PER_MINUTE = 60 * MILLISEC_PER_SECOND;
private static long MILLISEC_PER_HOUR = 60 * MILLISEC_PER_MINUTE;
private static long MILLISEC_PER_DAY = 24 * MILLISEC_PER_HOUR;
public byte getDays() {
return (byte) Math.floorDiv(getValue(), MILLISEC_PER_DAY);
}
public byte getHours() {
long hours = getValue() - (getDays() * MILLISEC_PER_DAY);
return (byte) Math.floorDiv(hours, MILLISEC_PER_HOUR);
}
public byte getMinutes() {
long minutes = getValue() - (getDays() * MILLISEC_PER_DAY) - (getHours() * MILLISEC_PER_HOUR);
return (byte) Math.floorDiv(minutes, MILLISEC_PER_MINUTE);
}
public byte getSeconds() {
long seconds = getValue() - (getDays() * MILLISEC_PER_DAY) - (getHours() * MILLISEC_PER_HOUR)
- (getMinutes() * MILLISEC_PER_MINUTE);
return (byte) Math.floorDiv(seconds, MILLISEC_PER_SECOND);
}
public int getMilliseconds() {
long milliseconds = getValue() - (getDays() * MILLISEC_PER_DAY) - (getHours() * MILLISEC_PER_HOUR)
- (getMinutes() * MILLISEC_PER_MINUTE) - (getSeconds() * MILLISEC_PER_SECOND);
return (int) milliseconds;
}
public Duration getDuration(Timed firstEvent, Timed secondEvent) {
Duration duration = ApogyCommonEMFFactory.eINSTANCE.createDuration();
long durationValue = 0;
if (firstEvent != null & firstEvent.getTime() != null && secondEvent != null && secondEvent.getTime() != null) {
durationValue = secondEvent.getTime().getTime() - firstEvent.getTime().getTime();
}
duration.setValue(durationValue);
return duration;
}
} // DurationImpl