Skip to content

Commit e1d92dc

Browse files
hasLongYear was giving wrong result (#680)
* hasLongYear was giving wrong result Issue:101533 * Revert "hasLongYear was giving wrong result" This reverts commit 934d354. * If date's length is 23 then it's full year * ctotex tests --------- Co-authored-by: tomas-sexenian <[email protected]>
1 parent e9abea4 commit e1d92dc

File tree

2 files changed

+47
-1
lines changed

2 files changed

+47
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1030,7 +1030,7 @@ private static boolean hasLongYear(String date)
10301030
if (!getBLANK_EMPTY_DATE() && date.indexOf(" ") != -1)
10311031
return true;
10321032

1033-
return date.length() == 10 || date.length() == 19;
1033+
return date.length() == 10 || date.length() == 19 || date.length() == 23;
10341034
}
10351035

10361036
public Date ctotex(String date, int format)

java/src/test/java/com/genexus/util/TestDateMethods.java

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,50 @@ public void testYearLimit(){
4242
calendar.setTime(testDate2);
4343
Assert.assertTrue(calendar.get(Calendar.YEAR) == 1976);
4444
}
45+
46+
@Test
47+
public void testCtotex(){
48+
Connect.init();
49+
50+
LocalUtil localUtil = new LocalUtil('.', "MDY", "24", 30, "eng");
51+
Date testDate1 = CommonUtil.nullDate();
52+
Date testDate2 = CommonUtil.nullDate();
53+
Date testDate3 = CommonUtil.nullDate();
54+
try
55+
{
56+
testDate1 = localUtil.ctotex("1930-01-01T00:00", 0);
57+
testDate2 = localUtil.ctotex("2023-01-01T00:00:00", 0);
58+
testDate3 = localUtil.ctotex("2200-12-31T00:00:00.000", 0);
59+
}
60+
catch (Exception e)
61+
{ }
62+
63+
Calendar calendar = GregorianCalendar.getInstance();
64+
calendar.setTime(testDate1);
65+
Assert.assertTrue(calendar.get(Calendar.YEAR) == 1930);
66+
calendar.setTime(testDate2);
67+
Assert.assertTrue(calendar.get(Calendar.YEAR) == 2023);
68+
calendar.setTime(testDate3);
69+
Assert.assertTrue(calendar.get(Calendar.YEAR) == 2200);
70+
71+
testDate1 = CommonUtil.nullDate();
72+
testDate2 = CommonUtil.nullDate();
73+
testDate3 = CommonUtil.nullDate();
74+
try
75+
{
76+
testDate1 = localUtil.ctotex("29-01-01", 0);
77+
testDate2 = localUtil.ctotex("30-01-01T00", 0);
78+
testDate3 = localUtil.ctotex("31-12-31T00:00", 0);
79+
}
80+
catch (Exception e)
81+
{ }
82+
83+
calendar = GregorianCalendar.getInstance();
84+
calendar.setTime(testDate1);
85+
Assert.assertTrue(calendar.get(Calendar.YEAR) == 2029);
86+
calendar.setTime(testDate2);
87+
Assert.assertTrue(calendar.get(Calendar.YEAR) == 1930);
88+
calendar.setTime(testDate3);
89+
Assert.assertTrue(calendar.get(Calendar.YEAR) == 1931);
90+
}
4591
}

0 commit comments

Comments
 (0)