/*
    PIP - Platform Independent Primitives
    Time units
    Ivan Pelipenko peri4ko@yandex.ru

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU Lesser General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

#include "piunits_class_time.h"


PIString PIUnits::Class::Time::name(int type) const {
	switch (type) {
	case Second: return "second"_tr("PIUnitsTime");
	case Hertz: return "hertz"_tr("PIUnitsTime");
	}
	return Class::Internal::unknown;
}


PIString PIUnits::Class::Time::unit(int type) const {
	switch (type) {
	case Second: return "s"_tr("PIUnitsTime");
	case Hertz: return "Hz"_tr("PIUnitsTime");
	}
	return Class::Internal::unknown;
}


double PIUnits::Class::Time::convert(double v, int from, int to) const {
	if (piCompared(v, 0.)) return 0.;
	switch (to) {
	case Second: return 1. / v;
	case Hertz: return 1. / v;
	}
	return v;
}


PIString PIUnits::Class::Time::valueToString(double v, char format, int prec) const {
	return PIString::fromNumber(v, format, prec);
}


bool PIUnits::Class::Time::supportPrefixes(int type) const {
	return true;
}


bool PIUnits::Class::Time::supportPrefixesNon3(int type) const {
	return false;
}


bool PIUnits::Class::Time::supportPrefixesGreater(int type) const {
	if (type == Hertz) return true;
	return false;
}


bool PIUnits::Class::Time::supportPrefixesSmaller(int type) const {
	if (type == Second) return true;
	return false;
}
