The sales tax rate has changed from 8% to 10%.
The tax rate is
public static final String TAX_PERCENT = "0.08";
It is dangerous to have it as a constant like this.
April 2014 8% October 2019 10%
The tax rate has changed in this way, and it is expected that the timing of tax increases will occur in the future.
Since the tax rate changes depending on the date and time in this way, it is recommended to prepare a method that returns the tax rate as shown below.
public static final String EIGHT_TAX_PERCENT = "0.08";
public static final String TEN_TAX_PERCENT = "0.10";
public static final String TEN_TAX_PERCENT_CHANGE_DAY = "2019-10-01 00:00:00";
public static BigDecimal getTaxPercent() {
try {
Date now = new Date();
SimpleDateFormat sdformat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date dateTime = sdformat.parse(TEN_TAX_PERCENT_CHANGE_DAY);
return now.getTime() >= dateTime.getTime()
? new BigDecimal(TEN_TAX_PERCENT)
: new BigDecimal(EIGHT_TAX_PERCENT);
} catch (ParseException e) {
System.out.println(e);
}
//I'm sure it won't come forever
return new BigDecimal("0");
}
Recommended Posts