/// <summary> /// 将int值转换为时间点 /// </summary> /// <param name="value"></param> /// <returns></returns> public static Instant FromInt(int value) { var segments = SplitToIntSegments(value); if (YearMonthDayInstant.TryParseSegments(segments, out var dInst)) { return(dInst); } else if (YearMonthInstant.TryParseSegments(segments, out var ymInst)) { return(ymInst); } else if (YearQuarterInstant.TryParseSegments(segments, out var yqInst)) { return(yqInst); } else if (YearHalfYearInstant.TryParseSegments(segments, out var yhInst)) { return(yhInst); } else if (YearInstant.TryParseSegments(segments, out var yInst)) { return(yInst); } else { throw new ArgumentException(nameof(value), $"无法将值 {value} 转换为时间点"); } }
/// <summary> /// 尝试从int型片段转换为实例 /// </summary> /// <param name="segments"></param> /// <param name="instant"></param> /// <returns></returns> internal static bool TryParseSegments(int[] segments, out YearMonthInstant instant) { var year = segments[0]; var month = segments[1] - (int)InstantType.Jan + 1; if (IsValidMonth(month)) { instant = new YearMonthInstant(year, month); return(true); } instant = null; return(false); }