Skip to content

Commit 12f48db

Browse files
authored
applyYearLimit method was not working since JDK 1.8 refactoring. (#441)
* applyYearLimit method was not working since JDK 1.8 refactoring. A unit test is added to avoid future problems. Issue: 91426 SAC #39703 * applyYearLimit method was not working since JDK 1.8 refactoring. A unit test is added to avoid future problems. Issue: 91426 SAC #39703
1 parent ec9ecfa commit 12f48db

File tree

2 files changed

+53
-4
lines changed

2 files changed

+53
-4
lines changed

common/src/main/java/com/genexus/LocalUtil.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2072,19 +2072,23 @@ public Date applyYearLimit(Date dateTime, String picture)
20722072
return dateTime;
20732073
}
20742074

2075+
Calendar currentCalendar = GregorianCalendar.getInstance();
2076+
currentCalendar.setTime(new Date());
2077+
20752078
Calendar calendar = GregorianCalendar.getInstance();
20762079
calendar.setTime(dateTime);
20772080
if (calendar.get(Calendar.YEAR) % 100 < firstYear2K)
20782081
{
2079-
if (calendar.get(Calendar.YEAR) < 100)
2082+
if (calendar.get(Calendar.YEAR) -100 < 1900 )
20802083
calendar.set(Calendar.YEAR, calendar.get(Calendar.YEAR) + 100);
20812084
}
2082-
else if (calendar.get(Calendar.YEAR) > 100)
2085+
else
20832086
{
2084-
calendar.set(Calendar.YEAR, calendar.get(Calendar.YEAR) - 100);
2087+
if (calendar.get(Calendar.YEAR) > currentCalendar.get(Calendar.YEAR))
2088+
calendar.set(Calendar.YEAR, calendar.get(Calendar.YEAR) - 100);
20852089
}
20862090

2087-
return dateTime;
2091+
return calendar.getTime();
20882092
}
20892093

20902094
public String getDateTimePicture(String dateTime)
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package com.genexus.util;
2+
3+
import com.genexus.Application;
4+
import com.genexus.CommonUtil;
5+
import com.genexus.LocalUtil;
6+
7+
import java.text.ParseException;
8+
import java.util.Calendar;
9+
import java.util.Date;
10+
import java.util.GregorianCalendar;
11+
import java.util.TimeZone;
12+
13+
import com.genexus.specific.java.Connect;
14+
import org.junit.Assert;
15+
import org.junit.Test;
16+
17+
public class TestDateMethods {
18+
19+
@Test
20+
public void testYearLimit(){
21+
Connect.init();
22+
LocalUtil localUtil = new LocalUtil('.', "MDY", "24", 30, "eng");
23+
Date testDate1 = CommonUtil.nullDate();
24+
Date testDate2 = CommonUtil.nullDate();
25+
26+
String pattern = "dd/MM/yy";
27+
28+
GXSimpleDateFormat df = new GXSimpleDateFormat(pattern);
29+
df.setTimeZone(TimeZone.getDefault());
30+
try
31+
{
32+
testDate1 = localUtil.applyYearLimit(df.parse("12/12/30"), pattern);
33+
testDate2 = localUtil.applyYearLimit(df.parse("08/05/76"), pattern);
34+
}
35+
catch (ParseException e)
36+
{
37+
38+
}
39+
Calendar calendar = GregorianCalendar.getInstance();
40+
calendar.setTime(testDate1);
41+
Assert.assertTrue(calendar.get(Calendar.YEAR) == 1930);
42+
calendar.setTime(testDate2);
43+
Assert.assertTrue(calendar.get(Calendar.YEAR) == 1976);
44+
}
45+
}

0 commit comments

Comments
 (0)