@@ -1823,7 +1823,7 @@ public Operand VisitYEAR_fun(mathParser.YEAR_funContext context)
18231823 {
18241824 var firstValue = this . Visit ( context . expr ( ) ) . ToMyDate ( "Function YEAR parameter is error!" ) ;
18251825 if ( firstValue . IsError ) { return firstValue ; }
1826- if ( firstValue . DateValue . Year == null ) {
1826+ if ( firstValue . DateValue . Year == null ) {
18271827 return Operand . Error ( "Function YEAR is error!" ) ;
18281828 }
18291829 return Operand . Create ( firstValue . DateValue . Year . Value ) ;
@@ -1949,7 +1949,13 @@ public Operand VisitDATEDIF_fun(mathParser.DATEDIF_funContext context)
19491949 #region md
19501950 var mo = endMyDate . Day - startMyDate . Day ;
19511951 if ( mo < 0 ) {
1952- var days = new DateTime ( startMyDate . Year , startMyDate . Month + 1 , 1 ) . AddDays ( - 1 ) . Day ;
1952+ int days ;
1953+ if ( startMyDate . Month == 12 ) {
1954+ days = new DateTime ( startMyDate . Year + 1 , 1 , 1 ) . AddDays ( - 1 ) . Day ;
1955+ } else {
1956+ days = new DateTime ( startMyDate . Year , startMyDate . Month + 1 , 1 ) . AddDays ( - 1 ) . Day ;
1957+
1958+ }
19531959 mo += days ;
19541960 }
19551961 return Operand . Create ( ( mo ) ) ;
@@ -1989,19 +1995,39 @@ public Operand VisitDAYS360_fun(mathParser.DAYS360_funContext context)
19891995 if ( endMyDate . Day == 31 ) days += 30 ;
19901996 if ( startMyDate . Day == 31 ) days -= 30 ;
19911997 } else {
1992- if ( startMyDate . Day == new DateTime ( startMyDate . Year , startMyDate . Month + 1 , 1 ) . AddDays ( - 1 ) . Day ) {
1993- days -= 30 ;
1998+ if ( startMyDate . Month == 12 ) {
1999+ if ( startMyDate . Day == new DateTime ( startMyDate . Year + 1 , 1 , 1 ) . AddDays ( - 1 ) . Day ) {
2000+ days -= 30 ;
2001+ } else {
2002+ days -= startMyDate . Day ;
2003+ }
19942004 } else {
1995- days -= startMyDate . Day ;
2005+ if ( startMyDate . Day == new DateTime ( startMyDate . Year , startMyDate . Month + 1 , 1 ) . AddDays ( - 1 ) . Day ) {
2006+ days -= 30 ;
2007+ } else {
2008+ days -= startMyDate . Day ;
2009+ }
19962010 }
1997- if ( endMyDate . Day == new DateTime ( endMyDate . Year , endMyDate . Month + 1 , 1 ) . AddDays ( - 1 ) . Day ) {
1998- if ( startMyDate . Day < 30 ) {
1999- days += 31 ;
2011+ if ( endMyDate . Month == 12 ) {
2012+ if ( endMyDate . Day == new DateTime ( endMyDate . Year + 1 , 1 , 1 ) . AddDays ( - 1 ) . Day ) {
2013+ if ( startMyDate . Day < 30 ) {
2014+ days += 31 ;
2015+ } else {
2016+ days += 30 ;
2017+ }
20002018 } else {
2001- days += 30 ;
2019+ days += endMyDate . Day ;
20022020 }
20032021 } else {
2004- days += endMyDate . Day ;
2022+ if ( endMyDate . Day == new DateTime ( endMyDate . Year , endMyDate . Month + 1 , 1 ) . AddDays ( - 1 ) . Day ) {
2023+ if ( startMyDate . Day < 30 ) {
2024+ days += 31 ;
2025+ } else {
2026+ days += 30 ;
2027+ }
2028+ } else {
2029+ days += endMyDate . Day ;
2030+ }
20052031 }
20062032 }
20072033 return Operand . Create ( days ) ;
@@ -3117,11 +3143,11 @@ public Operand VisitREGEX_fun(mathParser.REGEX_funContext context)
31173143 var secondValue = args [ 1 ] . ToText ( "Function REGEX parameter 2 is error!" ) ;
31183144 if ( secondValue . IsError ) { return secondValue ; }
31193145
3120- var b = Regex . Match ( firstValue . TextValue , secondValue . TextValue ) ;
3121- if ( b . Success == false ) {
3122- return Operand . Error ( "Function REGEX is error!" ) ;
3123- }
3124- return Operand . Create ( b . Value ) ;
3146+ var b = Regex . Match ( firstValue . TextValue , secondValue . TextValue ) ;
3147+ if ( b . Success == false ) {
3148+ return Operand . Error ( "Function REGEX is error!" ) ;
3149+ }
3150+ return Operand . Create ( b . Value ) ;
31253151 }
31263152 public Operand VisitREGEXREPALCE_fun ( mathParser . REGEXREPALCE_funContext context )
31273153 {
@@ -3213,7 +3239,7 @@ public Operand VisitSHA512_fun(mathParser.SHA512_funContext context)
32133239 }
32143240 return Operand . Error ( "Function SHA512 is error!" ) ;
32153241 }
3216-
3242+
32173243 public Operand VisitCRC32_fun ( mathParser . CRC32_funContext context )
32183244 {
32193245 var args = new List < Operand > ( ) ; int index = 1 ;
@@ -3275,7 +3301,7 @@ public Operand VisitHMACSHA256_fun(mathParser.HMACSHA256_funContext context)
32753301 }
32763302 var t = Hash . GetHmacSha256String ( encoding . GetBytes ( args [ 0 ] . TextValue ) , args [ 1 ] . TextValue ) ;
32773303 return Operand . Create ( t ) ;
3278- } catch ( Exception ) { }
3304+ } catch ( Exception ) { }
32793305 return Operand . Error ( "Function HMACSHA256 is error!" ) ;
32803306 }
32813307 public Operand VisitHMACSHA512_fun ( mathParser . HMACSHA512_funContext context )
@@ -3291,7 +3317,7 @@ public Operand VisitHMACSHA512_fun(mathParser.HMACSHA512_funContext context)
32913317 }
32923318 var t = Hash . GetHmacSha512String ( encoding . GetBytes ( args [ 0 ] . TextValue ) , args [ 1 ] . TextValue ) ;
32933319 return Operand . Create ( t ) ;
3294- } catch ( Exception ) { }
3320+ } catch ( Exception ) { }
32953321 return Operand . Error ( "Function HMACSHA512 is error!" ) ;
32963322 }
32973323 public Operand VisitTRIMSTART_fun ( mathParser . TRIMSTART_funContext context )
0 commit comments