Skip to content

Commit 664cb2c

Browse files
authored
Remove some deprecated procs from std/times (#14129)
1 parent b8d7a98 commit 664cb2c

File tree

2 files changed

+32
-144
lines changed

2 files changed

+32
-144
lines changed

lib/pure/times.nim

Lines changed: 31 additions & 143 deletions
Original file line numberDiff line numberDiff line change
@@ -225,24 +225,15 @@ elif defined(posix):
225225

226226
type CTime = posix.Time
227227

228-
when not defined(freebsd) and not defined(netbsd) and not defined(openbsd):
229-
var timezone {.importc, header: "<time.h>".}: int
230-
when not defined(valgrind_workaround_10121):
231-
tzset()
232-
233228
when defined(macosx):
234229
proc gettimeofday(tp: var Timeval, unused: pointer = nil)
235230
{.importc: "gettimeofday", header: "<sys/time.h>", sideEffect.}
236231

237232
elif defined(windows):
238233
import winlean, std/time_t
239234

240-
type CTime = time_t.Time
241-
242-
# visual c's c runtime exposes these under a different name
243-
var timezone {.importc: "_timezone", header: "<time.h>".}: int
244-
245235
type
236+
CTime = time_t.Time
246237
Tm {.importc: "struct tm", header: "<time.h>", final, pure.} = object
247238
tm_sec*: cint ## Seconds [0,60].
248239
tm_min*: cint ## Minutes [0,59].
@@ -2507,7 +2498,7 @@ proc `-=`*(t: var Time, b: TimeInterval) =
25072498
#
25082499

25092500
proc epochTime*(): float {.tags: [TimeEffect].} =
2510-
## gets time after the UNIX epoch (1970) in seconds. It is a float
2501+
## Gets time after the UNIX epoch (1970) in seconds. It is a float
25112502
## because sub-second resolution is likely to be supported (depending
25122503
## on the hardware/OS).
25132504
##
@@ -2545,7 +2536,7 @@ when not defined(js):
25452536
clocksPerSec {.importc: "CLOCKS_PER_SEC", nodecl, used.}: int
25462537

25472538
proc cpuTime*(): float {.tags: [TimeEffect].} =
2548-
## gets time spent that the CPU spent to run the current process in
2539+
## Gets time spent that the CPU spent to run the current process in
25492540
## seconds. This may be more useful for benchmarking than ``epochTime``.
25502541
## However, it may measure the real time instead (depending on the OS).
25512542
## The value of the result has no meaning.
@@ -2581,40 +2572,34 @@ proc countLeapYears*(yearSpan: int): int
25812572
## counts the number of leap years up to January 1st of a given year.
25822573
## Keep in mind that if specified year is a leap year, the leap day
25832574
## has not happened before January 1st of that year.
2584-
##
2585-
## **Deprecated since v0.20.0**.
2575+
# Deprecated since v0.20.0
25862576
(yearSpan - 1) div 4 - (yearSpan - 1) div 100 + (yearSpan - 1) div 400
25872577

25882578
proc countDays*(yearSpan: int): int
25892579
{.deprecated.} =
25902580
## Returns the number of days spanned by a given number of years.
2591-
##
2592-
## **Deprecated since v0.20.0**.
2581+
# Deprecated since v0.20.0
25932582
(yearSpan - 1) * 365 + countLeapYears(yearSpan)
25942583

25952584
proc countYears*(daySpan: int): int
25962585
{.deprecated.} =
25972586
## Returns the number of years spanned by a given number of days.
2598-
##
2599-
## **Deprecated since v0.20.0**.
2587+
# Deprecated since v0.20.0
26002588
((daySpan - countLeapYears(daySpan div 365)) div 365)
26012589

26022590
proc countYearsAndDays*(daySpan: int): tuple[years: int, days: int]
26032591
{.deprecated.} =
26042592
## Returns the number of years spanned by a given number of days and the
26052593
## remainder as days.
2606-
##
2607-
## **Deprecated since v0.20.0**.
2594+
# Deprecated since v0.20.0
26082595
let days = daySpan - countLeapYears(daySpan div 365)
26092596
result.years = days div 365
26102597
result.days = days mod 365
26112598

26122599
proc toTimeInterval*(time: Time): TimeInterval
2613-
{.deprecated: "Use `between` instead".} =
2600+
{.deprecated: "Use 'between' instead".} =
26142601
## Converts a Time to a TimeInterval. To be used when diffing times.
2615-
##
2616-
## **Deprecated since version 0.20.0:** Use the `between proc
2617-
## <#between,DateTime,DateTime>`_ instead.
2602+
# Deprecated since version 0.20.0
26182603
runnableExamples:
26192604
let a = fromUnix(10)
26202605
let b = fromUnix(1_500_000_000)
@@ -2625,55 +2610,45 @@ proc toTimeInterval*(time: Time): TimeInterval
26252610
dt.monthday, 0, dt.month.ord - 1, dt.year)
26262611

26272612
proc weeks*(dur: Duration): int64
2628-
{.inline, deprecated: "Use `inWeeks` instead".} =
2613+
{.inline, deprecated: "Use 'inWeeks' instead".} =
26292614
## Number of whole weeks represented by the duration.
2630-
##
2631-
## **Deprecated since version v0.20.0**: Use the `inWeeks proc
2632-
## <#inWeeks,Duration>`_ instead.
2615+
# Deprecated since version v0.20.0
26332616
runnableExamples:
26342617
let dur = initDuration(weeks = 1, days = 2, hours = 3, minutes = 4)
26352618
doAssert dur.weeks == 1
26362619
dur.inWeeks
26372620

26382621
proc days*(dur: Duration): int64
2639-
{.inline, deprecated: "Use `inDays` instead".} =
2622+
{.inline, deprecated: "Use 'inDays' instead".} =
26402623
## Number of whole days represented by the duration.
2641-
##
2642-
## **Deprecated since version v0.20.0**: Use the `inDays proc
2643-
## <#inDays,Duration>`_ instead.
2624+
# Deprecated since version v0.20.0
26442625
runnableExamples:
26452626
let dur = initDuration(weeks = 1, days = 2, hours = 3, minutes = 4)
26462627
doAssert dur.days == 9
26472628
dur.inDays
26482629

26492630
proc hours*(dur: Duration): int64
2650-
{.inline, deprecated: "Use `inHours` instead".} =
2631+
{.inline, deprecated: "Use 'inHours' instead".} =
26512632
## Number of whole hours represented by the duration.
2652-
##
2653-
## **Deprecated since version v0.20.0**: Use the `inHours proc
2654-
## <#inHours,Duration>`_ instead.
2633+
# Deprecated since version v0.20.0
26552634
runnableExamples:
26562635
let dur = initDuration(days = 1, hours = 2, minutes = 3)
26572636
doAssert dur.hours == 26
26582637
dur.inHours
26592638

26602639
proc minutes*(dur: Duration): int64
2661-
{.inline, deprecated: "Use `inMinutes` instead".} =
2640+
{.inline, deprecated: "Use 'inMinutes' instead".} =
26622641
## Number of whole minutes represented by the duration.
2663-
##
2664-
## **Deprecated since version v0.20.0**: Use the `inMinutes proc
2665-
## <#inMinutes,Duration>`_ instead.
2642+
# Deprecated since version v0.20.0
26662643
runnableExamples:
26672644
let dur = initDuration(days = 1, hours = 2, minutes = 3)
26682645
doAssert dur.minutes == 1563
26692646
dur.inMinutes
26702647

26712648
proc seconds*(dur: Duration): int64
2672-
{.inline, deprecated: "Use `inSeconds` instead".} =
2649+
{.inline, deprecated: "Use 'inSeconds' instead".} =
26732650
## Number of whole seconds represented by the duration.
2674-
##
2675-
## **Deprecated since version v0.20.0**: Use the `inSeconds proc
2676-
## <#inSeconds,Duration>`_ instead.
2651+
# Deprecated since version v0.20.0
26772652
runnableExamples:
26782653
let dur = initDuration(minutes = 10, seconds = 30)
26792654
doAssert dur.seconds == 630
@@ -2682,8 +2657,7 @@ proc seconds*(dur: Duration): int64
26822657
proc milliseconds*(dur: Duration): int {.inline, deprecated.} =
26832658
## Number of whole milliseconds represented by the **fractional**
26842659
## part of the duration.
2685-
##
2686-
## **Deprecated since version v0.20.0**.
2660+
# Deprecated since version v0.20.0
26872661
runnableExamples:
26882662
let dur = initDuration(minutes = 5, seconds = 6, milliseconds = 7,
26892663
microseconds = 8, nanoseconds = 9)
@@ -2693,8 +2667,7 @@ proc milliseconds*(dur: Duration): int {.inline, deprecated.} =
26932667
proc microseconds*(dur: Duration): int {.inline, deprecated.} =
26942668
## Number of whole microseconds represented by the **fractional**
26952669
## part of the duration.
2696-
##
2697-
## **Deprecated since version v0.20.0**.
2670+
# Deprecated since version v0.20.0
26982671
runnableExamples:
26992672
let dur = initDuration(minutes = 5, seconds = 6, milliseconds = 7,
27002673
microseconds = 8, nanoseconds = 9)
@@ -2704,8 +2677,7 @@ proc microseconds*(dur: Duration): int {.inline, deprecated.} =
27042677
proc nanoseconds*(dur: Duration): NanosecondRange {.inline, deprecated.} =
27052678
## Number of whole microseconds represented by the **fractional**
27062679
## part of the duration.
2707-
##
2708-
## **Deprecated since version v0.20.0**.
2680+
# Deprecated since version v0.20.0
27092681
runnableExamples:
27102682
let dur = initDuration(minutes = 5, seconds = 6, milliseconds = 7,
27112683
microseconds = 8, nanoseconds = 9)
@@ -2714,121 +2686,37 @@ proc nanoseconds*(dur: Duration): NanosecondRange {.inline, deprecated.} =
27142686

27152687
proc fractional*(dur: Duration): Duration {.inline, deprecated.} =
27162688
## The fractional part of `dur`, as a duration.
2717-
##
2718-
## **Deprecated since version v0.20.0**.
2689+
# Deprecated since version v0.20.0
27192690
runnableExamples:
27202691
let dur = initDuration(minutes = 5, seconds = 6, milliseconds = 7,
27212692
microseconds = 8, nanoseconds = 9)
27222693
doAssert dur.fractional == initDuration(milliseconds = 7, microseconds = 8,
27232694
nanoseconds = 9)
27242695
initDuration(nanoseconds = dur.nanosecond)
27252696

2726-
when not defined(js):
2727-
proc unixTimeToWinTime*(time: CTime): int64
2728-
{.deprecated: "Use toWinTime instead".} =
2729-
## Converts a UNIX `Time` (``time_t``) to a Windows file time
2730-
##
2731-
## **Deprecated:** use ``toWinTime`` instead.
2732-
result = int64(time) * rateDiff + epochDiff
2733-
2734-
proc winTimeToUnixTime*(time: int64): CTime
2735-
{.deprecated: "Use fromWinTime instead".} =
2736-
## Converts a Windows time to a UNIX `Time` (``time_t``)
2737-
##
2738-
## **Deprecated:** use ``fromWinTime`` instead.
2739-
result = CTime((time - epochDiff) div rateDiff)
2740-
2741-
proc initInterval*(seconds, minutes, hours, days, months, years: int = 0):
2742-
TimeInterval {.deprecated.} =
2743-
## **Deprecated since v0.18.0:** use ``initTimeInterval`` instead.
2744-
initTimeInterval(0, 0, 0, seconds, minutes, hours, days, 0, months, years)
2745-
27462697
proc fromSeconds*(since1970: float): Time
2747-
{.tags: [], raises: [], benign, deprecated: "Use fromUnixFloat or fromUnix".} =
2698+
{.tags: [], raises: [], benign, deprecated: "Use `fromUnixFloat or 'fromUnix' instead".} =
27482699
## Takes a float which contains the number of seconds since the unix epoch and
27492700
## returns a time object.
2750-
##
2751-
## **Deprecated since v0.18.0:** use ``fromUnix`` instead
2701+
# Deprecated since v0.18.0
27522702
fromUnixFloat(since1970)
27532703

27542704
proc fromSeconds*(since1970: int64): Time
2755-
{.tags: [], raises: [], benign, deprecated.} =
2705+
{.tags: [], raises: [], benign, deprecated: "Use 'fromUnix' instead".} =
27562706
## Takes an int which contains the number of seconds since the unix epoch and
27572707
## returns a time object.
2758-
##
2759-
## **Deprecated since v0.18.0:** use ``fromUnix`` instead
2708+
# Deprecated since v0.18.0
27602709
fromUnix(since1970)
27612710

27622711
proc toSeconds*(time: Time): float
2763-
{.tags: [], raises: [], benign, deprecated: "Use toUnixFloat or toUnix".} =
2712+
{.tags: [], raises: [], benign, deprecated: "Use 'toUnixFloat' or 'toUnix' instead".} =
27642713
## Returns the time in seconds since the unix epoch, with subsecond resolution.
2714+
# Deprecated since v0.18.0
27652715
toUnixFloat(time)
27662716

2767-
proc getLocalTime*(time: Time): DateTime
2768-
{.tags: [], raises: [], benign, deprecated.} =
2769-
## Converts the calendar time `time` to broken-time representation,
2770-
## expressed relative to the user's specified time zone.
2771-
##
2772-
## **Deprecated since v0.18.0:** use ``local`` instead
2773-
time.local
2774-
27752717
proc getGMTime*(time: Time): DateTime
2776-
{.tags: [], raises: [], benign, deprecated.} =
2718+
{.tags: [], raises: [], benign, deprecated: "Use 'utc' instead".} =
27772719
## Converts the calendar time `time` to broken-down time representation,
27782720
## expressed in Coordinated Universal Time (UTC).
2779-
##
2780-
## **Deprecated since v0.18.0:** use ``utc`` instead
2721+
# Deprecated since v0.18.0
27812722
time.utc
2782-
2783-
proc getTimezone*(): int
2784-
{.tags: [TimeEffect], raises: [], benign, deprecated.} =
2785-
## Returns the offset of the local (non-DST) timezone in seconds west of UTC.
2786-
##
2787-
## **Deprecated since v0.18.0:** use ``now().utcOffset`` to get the current
2788-
## utc offset (including DST).
2789-
when defined(js):
2790-
return newDate().getTimezoneOffset() * 60
2791-
elif defined(freebsd) or defined(netbsd) or defined(openbsd):
2792-
# This is wrong since it will include DST offsets, but the behavior has
2793-
# always been wrong for bsd and the proc is deprecated so lets ignore it.
2794-
return now().utcOffset
2795-
else:
2796-
return timezone
2797-
2798-
proc getDayOfWeek*(day, month, year: int): WeekDay
2799-
{.tags: [], raises: [], benign, deprecated.} =
2800-
## **Deprecated since v0.18.0:** use
2801-
## ``getDayOfWeek(monthday: MonthdayRange; month: Month; year: int)`` instead.
2802-
getDayOfWeek(day, month.Month, year)
2803-
2804-
proc getDayOfWeekJulian*(day, month, year: int): WeekDay {.deprecated.} =
2805-
## Returns the day of the week enum from day, month and year,
2806-
## according to the Julian calendar.
2807-
## **Deprecated since v0.18.0**
2808-
# Day & month start from one.
2809-
let
2810-
a = (14 - month) div 12
2811-
y = year - a
2812-
m = month + (12*a) - 2
2813-
d = (5 + day + y + (y div 4) + (31*m) div 12) mod 7
2814-
result = d.WeekDay
2815-
2816-
proc adjTime*(zt: ZonedTime): Time
2817-
{.deprecated: "Use zt.time instead".} =
2818-
## **Deprecated since v0.19.0:** use the ``time`` field instead.
2819-
zt.time - initDuration(seconds = zt.utcOffset)
2820-
2821-
proc `adjTime=`*(zt: var ZonedTime, adjTime: Time)
2822-
{.deprecated: "Use zt.time instead".} =
2823-
## **Deprecated since v0.19.0:** use the ``time`` field instead.
2824-
zt.time = adjTime + initDuration(seconds = zt.utcOffset)
2825-
2826-
proc zoneInfoFromUtc*(zone: Timezone, time: Time): ZonedTime
2827-
{.deprecated: "Use zonedTimeFromTime instead".} =
2828-
## **Deprecated since v0.19.0:** use ``zonedTimeFromTime`` instead.
2829-
zone.zonedTimeFromTime(time)
2830-
2831-
proc zoneInfoFromTz*(zone: Timezone, adjTime: Time): ZonedTime
2832-
{.deprecated: "Use zonedTimeFromAdjTime instead".} =
2833-
## **Deprecated since v0.19.0:** use the ``zonedTimeFromAdjTime`` instead.
2834-
zone.zonedTimeFromAdjTime(adjTime)

tests/deps/jester-#head/jester.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -684,7 +684,7 @@ template uri*(address = "", absolute = true, addScriptName = true): untyped =
684684

685685
proc daysForward*(days: int): DateTime =
686686
## Returns a DateTime object referring to the current time plus ``days``.
687-
return getTime().utc + initInterval(days = days)
687+
return getTime().utc + initTimeInterval(days = days)
688688

689689
template setCookie*(name, value: string, expires="",
690690
sameSite: SameSite=Lax): typed =

0 commit comments

Comments
 (0)