Skip to content

v2.7.0

Choose a tag to compare

@gouguoyin gouguoyin released this 19 Oct 05:22
· 27 commits to master since this release
93491ca

English

✨ Features

  • Add AddWeekdays, AddWeekday, SubWeekdays, SubWeekday methods to skip weekend days when counting working days: moves over days while skipping the weekend days configured on the instance, so deadlines can be counted in working days; the four names mirror AddDays / AddDay / SubDays / SubDay, and weekend days are read from the instance so SetWeekendDays keeps working; when all seven days are marked as weekend days, each weekday span is capped to a whole week to prevent infinite loops (by @darakanoit in #366)
  • Add IsSameWeek method to check whether two dates fall in the same week: completes the IsSame* family (IsSameCentury, IsSameDecade, IsSameYear, IsSameQuarter, IsSameWeek, IsSameMonth, IsSameDay, IsSameHour, IsSameMinute, IsSameSecond); honours SetWeekStartsAt so two dates that share a week under one setting may not share it under another; the comparison is based on the date the week starts on, correctly handling year-boundary-crossing weeks (by @darakanoit in #368)
  • Add IsBirthday method to compare month and day for birthdays: reports whether two dates fall on the same month and day, ignoring the year; without an argument it compares with now; February 29 only matches February 29, so it is never a birthday in a common year, matching PHP Carbon behaviour (by @darakanoit in #364)
  • Add Asia/Jakarta timezone constant support (by @mirzaq19 in #374)

🐛 Fixes

  • Fix StartOfSecond and EndOfSecond selecting the wrong occurrence during daylight-saving rollbacks: during a repeated daylight-saving hour, time.Date reconstruction could select the other occurrence of the same local time; now copies the instance and adjusts the existing timestamp's subsecond precision instead, preserving the selected instant, location and configuration (by @mikamikasuki in #377)
  • Fix StartOfMinute and EndOfMinute selecting the wrong occurrence during daylight-saving rollbacks: same bug as #377 one level up; now copies the instance and subtracts the local seconds, keeping the instant, location and offset (by @dualfroz in #378)
  • Fix StartOfHour and EndOfHour selecting the wrong occurrence during daylight-saving rollbacks: preserves the receiver's occurrence when the reconstructed hour boundary has a valid counterpart with the receiver's offset; keeps the existing calendar reconstruction when no such counterpart exists, including Lord Howe's partial-hour transitions (by @dajiaohuang in #382)
  • Fix DiffInSeconds ignoring the sub-second part and counting inaccurately across second boundaries: subtracting whole-second timestamps ignored the fractional part, so a gap of 0.2s across a second boundary counted as a full second; now adjusts by one when the nanosecond difference has the opposite sign, counting whole seconds elapsed and truncated toward zero (by @youdie006 in #379)
  • Fix DiffInDays and DiffInWeeks computing incorrect results across DST transitions: dividing elapsed seconds gave wrong results when crossing a DST change; now counts calendar days the way DiffInMonths counts months (AddDate plus an adjustment), and DiffInWeeks uses it; only intervals that cross a DST transition change (by @youdie006 in #376)
  • Fix DiffInYears and DiffInMonths producing incorrect estimates when comparing dates across different time zones: the first estimate from each date's own Year() / Month() fields could be off when the two dates are in different locations; now reads the later date in the earlier date's location before taking the year and month fields, matching the frame DiffInDays uses (by @ybai08 in #384)
  • Fix IsSameDecade not comparing the century: Decade() is the decade within the century, so Parse("1995-08-05").IsSameDecade(Parse("2095-08-05")) returned true; now also compares Century(), matching the buckets StartOfDecade uses (by @youdie006 in #375)
  • Fix FromStdTime returning the wrong lunar date just after midnight when the zone's UTC offset differs from 1900: elapsed time from 1900-01-31 in the time's own zone leaked the two instants' offsets into the day count; now counts the days between the wall-clock dates in UTC, matching persian.FromStdTime and hebrew.FromStdTime (by @youdie006 in #380)
  • Fix race condition in frozen-clock mode where concurrent Sleep calls lost clock advances: concurrent Sleep calls on a frozen clock raced with each other and with Now, losing clock advances; now uses the existing frozen-clock mutex around the check and update (by @yuefdev in #383)

🔧 Dependencies

中文

✨ 新功能

  • 新增 AddWeekdays、AddWeekday、SubWeekdays、SubWeekday 方法,支持跳过周末日进行工作日计算:按实例配置的周末日跳过非工作日进行日期推移,方便按工作日计算截止日期;四个方法命名与 AddDays / AddDay / SubDays / SubDay 保持一致,周末日从实例读取因此 SetWeekendDays 仍生效;当七天全部被标记为周末日时,每个工作日跨度被限制为整周以防止死循环(by @darakanoit in #366)
  • 新增 IsSameWeek 方法,判断两个日期是否在同一周:补全 IsSame* 家族(IsSameCentury、IsSameDecade、IsSameYear、IsSameQuarter、IsSameWeek、IsSameMonth、IsSameDay、IsSameHour、IsSameMinute、IsSameSecond);尊重 SetWeekStartsAt 设置,因此同一组日期在不同设置下可能不属于同一周;比较基于周起始日期,正确处理跨年份的边界周(by @darakanoit in #368)
  • 新增 IsBirthday 方法,比较月日判断是否生日:判断两个日期是否落在同一月同日,忽略年份;无参数时与当前时间比较;2月29日仅匹配2月29日,平年永远不会是生日,与 PHP Carbon 行为一致(by @darakanoit in #364)
  • 新增 Asia/Jakarta 时区常量支持(by @mirzaq19 in #374)

🐛 修复

  • 修复夏令时回退期间 StartOfSecond 和 EndOfSecond 方法选择错误时间出现的问题:在重复的夏令时小时内,time.Date 重建可能选择同一本地时间的另一次出现;现在改为复制实例并调整现有时间戳的亚秒精度,保留选中的时刻、位置和配置(by @mikamikasuki in #377)
  • 修复夏令时回退期间 StartOfMinute 和 EndOfMinute 方法选择错误时间出现的问题:与 #377 同一类 bug,只是上升了一级;现在复制实例并减去本地秒数,保留时刻、位置和偏移(by @dualfroz in #378)
  • 修复夏令时回退期间 StartOfHour 和 EndOfHour 方法选择错误时间出现的问题:当重建的小时边界存在与接收器偏移一致的有效对应出现时,保留接收器的出现;不存在对应出现时(如 Lord Howe 的部分小时间隔回退)保持现有日历重建行为(by @dajiaohuang in #382)
  • 修复 DiffInSeconds 方法忽略亚秒部分导致跨秒边界计时不准确的问题:减去整秒时间戳时忽略了小数部分,导致跨越秒边界的 0.2 秒间隙被计为整秒;现在当纳秒差符号相反时调整 ±1,按已流逝的整秒计数并朝零截断(by @youdie006 in #379)
  • 修复 DiffInDays 和 DiffInWeeks 方法跨越夏令时转换时计算错误的问题:除以流逝秒数在跨越夏令时转换时给出错误结果;现在改为按日历日计数(与 DiffInMonths 按月计数方式一致,AddDate 加调整),DiffInWeeks 基于它计算;仅跨越夏令时转换的区间结果会变化(by @youdie006 in #376)
  • 修复 DiffInYears 和 DiffInMonths 方法在不同时区之间比较时估算错误的问题:从各自日期的 Year() / Month() 字段进行首次估算时,两个日期处于不同位置可能导致偏差;现在先以较早日期所在位置读取较晚日期,再取年月字段,与 DiffInDays 使用的框架一致(by @ybai08 in #384)
  • 修复 IsSameDecade 方法未比较世纪导致跨世纪日期误判的问题:Decade() 是世纪内的十年,因此 Parse("1995-08-05").IsSameDecade(Parse("2095-08-05")) 曾返回 true;现在也比较 Century(),与 StartOfDecade 使用的分桶一致(by @youdie006 in #375)
  • 修复 FromStdTime 方法在凌晨时刻因 UTC 偏移差异返回错误农历日期的问题:以时间所在时区计算从 1900-01-31 起流逝的时间,两个时刻的偏移会泄漏到日计数中;现在改为在 UTC 中计算挂钟日期之间的天数,与 persian.FromStdTime 和 hebrew.FromStdTime 一致(by @youdie006 in #380)
  • 修复冻结时钟模式下并发调用 Sleep 方法导致时钟推进丢失的竞态问题:冻结时钟上的并发 Sleep 调用彼此以及与 Now 发生竞态,导致时钟推进丢失;现在使用现有的冻结时钟互斥锁包裹检查和更新(by @yuefdev in #383)

🔧 依赖升级