diff --git a/YLErpDAL/Modules/UnderlyingModule/UnderlyingHelper.cs b/YLErpDAL/Modules/UnderlyingModule/UnderlyingHelper.cs
index 17936953..48fb0846 100644
--- a/YLErpDAL/Modules/UnderlyingModule/UnderlyingHelper.cs
+++ b/YLErpDAL/Modules/UnderlyingModule/UnderlyingHelper.cs
@@ -253,43 +253,22 @@ namespace YLErp.Modules.UnderlyingModule
/// 返回3.12格式
public static double? getYearTerm(DateTime? calcDate, DateTime? sourceDate)
{
- if (!calcDate.HasValue)
+ if (!calcDate.HasValue || !sourceDate.HasValue)
+ return null;
+
+ if (calcDate.Value > sourceDate.Value)
+ throw new ArgumentException("计算日期必须小于原日期", nameof(calcDate));
+
+ int totalMonths = (sourceDate.Value.Year - calcDate.Value.Year) * 12
+ + (sourceDate.Value.Month - calcDate.Value.Month);
+
+ if (sourceDate.Value.Day < calcDate.Value.Day)
{
- return null;//不限
+ totalMonths--;
}
- if (sourceDate.HasValue)
- {
- if (calcDate > sourceDate)
- {
- throw new ArgumentException("计算日期必须小于原日期", nameof(calcDate));
- }
- //计算sourceDate与calcDate年限差
- int yearDiff = sourceDate.Value.Year - calcDate.Value.Year;
- int monthDiff = sourceDate.Value.Month - calcDate.Value.Month;
- int dayDiff = sourceDate.Value.Day - calcDate.Value.Day;
- // 如果月差为负,说明还没到整年,需要向前借一年
- if (monthDiff < 0)
- {
- yearDiff -= 1;
- monthDiff += 12;
- }
-
- // 如果天数为负,说明还没到整月,需要向前借一个月
- if (dayDiff < 0)
- {
- monthDiff -= 1;
- if (monthDiff < 0)
- {
- yearDiff -= 1;
- monthDiff += 12;
- }
- }
-
- double yearTerm = yearDiff + monthDiff / 12.0;
- return yearTerm;
- }
- return null;//不限
+ double yearTerm = totalMonths / 12.0;
+ return yearTerm;
}
///
/// 根据标的发行年限和剩余期限计算适用保证金率