|
|
|
@ -52,7 +52,7 @@ public class DateDuration {
|
|
|
|
|
* 是否为有效时间区间,若用户指定了时间区间,但解析错误,其时间区间为0
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
public boolean Valid() {
|
|
|
|
|
public boolean valid() {
|
|
|
|
|
return this.bValid;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -124,7 +124,7 @@ public class DateDuration {
|
|
|
|
|
return strExtraString.toString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Divide(double val) {
|
|
|
|
|
public void divide(double val) {
|
|
|
|
|
if (val < PRECISION) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
@ -165,7 +165,7 @@ public class DateDuration {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!ValueValid()) {
|
|
|
|
|
if (!valueValid()) {
|
|
|
|
|
this.time = 0;
|
|
|
|
|
this.rate = 0.0f;
|
|
|
|
|
this.bValid = false;
|
|
|
|
@ -173,42 +173,35 @@ public class DateDuration {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ArrayList<EV_STRING> lst = new ArrayList<EV_STRING>();
|
|
|
|
|
Decompound(lst);
|
|
|
|
|
decompound(lst);
|
|
|
|
|
|
|
|
|
|
boolean oFlg = lst.size() == 1;
|
|
|
|
|
|
|
|
|
|
for (EV_STRING evs : lst) {
|
|
|
|
|
if (evs.type == EV_STRING_TYPE.EVS_GOOD)
|
|
|
|
|
{
|
|
|
|
|
AbstractMap.SimpleEntry<Boolean, Integer> extraTime = TransTime_Each(evs.value);
|
|
|
|
|
if (extraTime.getKey() || !oFlg)
|
|
|
|
|
{
|
|
|
|
|
if (evs.type == EV_STRING_TYPE.EVS_GOOD) {
|
|
|
|
|
AbstractMap.SimpleEntry<Boolean, Integer> extraTime = transTimeEach(evs.value);
|
|
|
|
|
if (extraTime.getKey() || !oFlg) {
|
|
|
|
|
this.time += extraTime.getValue();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
} else {
|
|
|
|
|
this.time += extraTime.getValue() * 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
AbstractMap.SimpleEntry<Boolean, Double> extraPer = TransRate_Each(evs.value);
|
|
|
|
|
if (extraPer.getKey())
|
|
|
|
|
{
|
|
|
|
|
else {
|
|
|
|
|
AbstractMap.SimpleEntry<Boolean, Double> extraPer = transRateEach(evs.value);
|
|
|
|
|
if (extraPer.getKey()) {
|
|
|
|
|
this.rate = extraPer.getValue();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (this.time < 0)
|
|
|
|
|
{
|
|
|
|
|
if (this.time < 0) {
|
|
|
|
|
this.time = 0;
|
|
|
|
|
this.rate = 0.0f;
|
|
|
|
|
this.bValid = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private boolean ValueValid() {
|
|
|
|
|
private boolean valueValid() {
|
|
|
|
|
for (char ch : this.value.toCharArray()) {
|
|
|
|
|
if (ch <= 'z' && ch >= 'a') {
|
|
|
|
|
ch -= 32;
|
|
|
|
@ -232,61 +225,46 @@ public class DateDuration {
|
|
|
|
|
|| ch == 'M' || ch == 'S' || ch == '+'||ch == '-'||ch == 'P');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Decompound(ArrayList<EV_STRING> lst) {
|
|
|
|
|
private void decompound(ArrayList<EV_STRING> lst) {
|
|
|
|
|
int len = this.value.length();
|
|
|
|
|
int iStr = 0;
|
|
|
|
|
EV_STRING evs = new EV_STRING();
|
|
|
|
|
evs.type = EV_STRING_TYPE.EVS_GOOD;
|
|
|
|
|
while(iStr < len)
|
|
|
|
|
{
|
|
|
|
|
while(iStr < len) {
|
|
|
|
|
char ch = this.value.charAt(iStr);
|
|
|
|
|
if (ch == '+')
|
|
|
|
|
{
|
|
|
|
|
if (ch == '+') {
|
|
|
|
|
lst.add(evs.clone());
|
|
|
|
|
evs.value = "";
|
|
|
|
|
evs.type = EV_STRING_TYPE.EVS_GOOD;
|
|
|
|
|
iStr++;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
else if (ch == '-')
|
|
|
|
|
{
|
|
|
|
|
} else if (ch == '-') {
|
|
|
|
|
int iPre = iStr;
|
|
|
|
|
if (iPre != 0)
|
|
|
|
|
{
|
|
|
|
|
if (iPre != 0) {
|
|
|
|
|
iPre--;
|
|
|
|
|
char cp = this.value.charAt(iPre);
|
|
|
|
|
if (!(cp == 'D' || cp == 'H'
|
|
|
|
|
|| cp == 'M' || cp == 'S'))
|
|
|
|
|
{
|
|
|
|
|
|| cp == 'M' || cp == 'S')) {
|
|
|
|
|
evs.value = evs.value + 'S';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (ch == 'P')
|
|
|
|
|
{
|
|
|
|
|
} else if (ch == 'P') {
|
|
|
|
|
int iTempIndex = 0;
|
|
|
|
|
StringBuffer temp1 = new StringBuffer();
|
|
|
|
|
StringBuffer temp2 = new StringBuffer();
|
|
|
|
|
int iTemp = evs.value.length() - 1;
|
|
|
|
|
for (;iTemp >= 0;iTemp--)
|
|
|
|
|
{
|
|
|
|
|
for (;iTemp >= 0;iTemp--) {
|
|
|
|
|
char cTemp = evs.value.charAt(iTemp);
|
|
|
|
|
if (cTemp == 'D' || cTemp == 'H'
|
|
|
|
|
|| cTemp == 'M' || cTemp == 'S')
|
|
|
|
|
{
|
|
|
|
|
|| cTemp == 'M' || cTemp == 'S') {
|
|
|
|
|
iTempIndex++;
|
|
|
|
|
}
|
|
|
|
|
if (iTempIndex >= 2)
|
|
|
|
|
{
|
|
|
|
|
} if (iTempIndex >= 2) {
|
|
|
|
|
temp1.insert(0,cTemp);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
} else {
|
|
|
|
|
temp2.insert(0,cTemp);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (!temp1.toString().isEmpty())
|
|
|
|
|
{
|
|
|
|
|
if (!temp1.toString().isEmpty()) {
|
|
|
|
|
EV_STRING evs1 = new EV_STRING();
|
|
|
|
|
evs1.type = EV_STRING_TYPE.EVS_GOOD;
|
|
|
|
|
evs1.value = temp1.toString();
|
|
|
|
@ -296,12 +274,10 @@ public class DateDuration {
|
|
|
|
|
evs.type = EV_STRING_TYPE.EVS_HAVE_P;
|
|
|
|
|
evs.value = evs.value + ch;
|
|
|
|
|
iStr++;
|
|
|
|
|
if (iStr != len)
|
|
|
|
|
{
|
|
|
|
|
if (iStr != len) {
|
|
|
|
|
char cp = this.value.charAt(iStr);
|
|
|
|
|
if (cp == 'D' || cp == 'H'
|
|
|
|
|
|| cp == 'M' || cp == 'S')
|
|
|
|
|
{
|
|
|
|
|
|| cp == 'M' || cp == 'S') {
|
|
|
|
|
evs.value = evs.value + cp;
|
|
|
|
|
iStr++;
|
|
|
|
|
}
|
|
|
|
@ -315,13 +291,12 @@ public class DateDuration {
|
|
|
|
|
evs.value = evs.value + ch;
|
|
|
|
|
iStr++;
|
|
|
|
|
}
|
|
|
|
|
if (!evs.value.isEmpty())
|
|
|
|
|
{
|
|
|
|
|
if (!evs.value.isEmpty()) {
|
|
|
|
|
lst.add(evs);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private AbstractMap.SimpleEntry<Boolean, Integer> TransTime_Each(String extraValue) {
|
|
|
|
|
private AbstractMap.SimpleEntry<Boolean, Integer> transTimeEach(String extraValue) {
|
|
|
|
|
if (extraValue.isEmpty())
|
|
|
|
|
return new AbstractMap.SimpleEntry<Boolean, Integer>(false, 0);
|
|
|
|
|
|
|
|
|
@ -330,16 +305,13 @@ public class DateDuration {
|
|
|
|
|
boolean flg = false;
|
|
|
|
|
for (int i = 0; i < extraValue.length(); i++) {
|
|
|
|
|
char ch = extraValue.charAt(i);
|
|
|
|
|
int rate = TimeUnit(ch);
|
|
|
|
|
if (rate > 0)
|
|
|
|
|
{
|
|
|
|
|
int rate = timeUnit(ch);
|
|
|
|
|
if (rate > 0) {
|
|
|
|
|
double iC = Double.parseDouble(temp.toString());
|
|
|
|
|
extraTime += (int)(iC*rate);
|
|
|
|
|
temp.setLength(0);
|
|
|
|
|
flg = true;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
} else {
|
|
|
|
|
temp.append(ch);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -347,7 +319,7 @@ public class DateDuration {
|
|
|
|
|
extraTime += Double.parseDouble(temp.toString());
|
|
|
|
|
return new AbstractMap.SimpleEntry<Boolean, Integer>(flg, extraTime);
|
|
|
|
|
}
|
|
|
|
|
private AbstractMap.SimpleEntry<Boolean, Double> TransRate_Each(String extraValue) {
|
|
|
|
|
private AbstractMap.SimpleEntry<Boolean, Double> transRateEach(String extraValue) {
|
|
|
|
|
if (extraValue.isEmpty())
|
|
|
|
|
return new AbstractMap.SimpleEntry<Boolean, Double>(false, 0.0);
|
|
|
|
|
|
|
|
|
@ -356,8 +328,7 @@ public class DateDuration {
|
|
|
|
|
boolean flg = false;
|
|
|
|
|
for (int i = 0; i < extraValue.length(); i++) {
|
|
|
|
|
char ch = extraValue.charAt(i);
|
|
|
|
|
switch(ch)
|
|
|
|
|
{
|
|
|
|
|
switch(ch) {
|
|
|
|
|
case 'D': extraPer = flg ? (1 / Double.parseDouble(temp.toString())) * 86400 : Double.parseDouble(temp.toString()) * 86400; return new AbstractMap.SimpleEntry<Boolean, Double>(true, extraPer);
|
|
|
|
|
case 'H': extraPer = flg ? (1 / Double.parseDouble(temp.toString())) * 3600: Double.parseDouble(temp.toString()) * 3600; return new AbstractMap.SimpleEntry<Boolean, Double>(true, extraPer);
|
|
|
|
|
case 'M': extraPer = flg ? (1 / Double.parseDouble(temp.toString())) * 60 : Double.parseDouble(temp.toString()) * 60; return new AbstractMap.SimpleEntry<Boolean, Double>(true, extraPer);
|
|
|
|
@ -366,12 +337,11 @@ public class DateDuration {
|
|
|
|
|
default : temp.append(ch);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return new AbstractMap.SimpleEntry<Boolean, Double>(true, extraPer);
|
|
|
|
|
return new AbstractMap.SimpleEntry<>(true, extraPer);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private int TimeUnit(char ch) {
|
|
|
|
|
switch(ch)
|
|
|
|
|
{
|
|
|
|
|
private int timeUnit(char ch) {
|
|
|
|
|
switch(ch) {
|
|
|
|
|
case 'D': return 86400;
|
|
|
|
|
case 'H': return 3600;
|
|
|
|
|
case 'M': return 60;
|
|
|
|
|