• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

JuliaLang / julia / #38162

06 Aug 2025 08:25PM UTC coverage: 25.688% (-43.6%) from 69.336%
#38162

push

local

web-flow
fix runtime cglobal builtin function implementation (#59210)

This had failed to be updated for the LazyLibrary changes to codegen.

12976 of 50513 relevant lines covered (25.69%)

676965.51 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

38.18
/stdlib/Dates/src/accessors.jl
1
# This file is a part of Julia. License is MIT: https://julialang.org/license
2

3
# Convert # of Rata Die days to proleptic Gregorian calendar y,m,d,w
4
# Reference: https://www.researchgate.net/profile/Peter-Baum/publication/316558298_Date_Algorithms/links/5f90c3f992851c14bcdb0da6/Date-Algorithms.pdf
5
function yearmonthday(days)
×
6
    z = days + 306; h = 100z - 25; a = fld(h, 3652425); b = a - fld(a, 4)
×
7
    y = fld(100b + h, 36525); c = b + z - 365y - fld(y, 4); m = div(5c + 456, 153)
×
8
    d = c - div(153m - 457, 5); return m > 12 ? (y + 1, m - 12, d) : (y, m, d)
×
9
end
10
function year(days)
23✔
11
   z = days + 306; h = 100z - 25; a = fld(h, 3652425); b = a - fld(a, 4)
23✔
12
   y = fld(100b + h, 36525); c = b + z - 365y - fld(y, 4); m = div(5c + 456, 153)
23✔
13
   return m > 12 ? y + 1 : y
23✔
14
end
15
function yearmonth(days)
×
16
    z = days + 306; h = 100z - 25; a = fld(h,3652425); b = a - fld(a,4)
×
17
    y = fld(100b + h, 36525); c = b + z - 365y - fld(y, 4); m = div(5c + 456, 153)
×
18
    return m > 12 ? (y + 1, m - 12) : (y, m)
×
19
end
20
function month(days)
23✔
21
    z = days + 306; h = 100z - 25; a = fld(h,3652425); b = a - fld(a,4)
23✔
22
    y = fld(100b + h, 36525); c = b + z - 365y - fld(y, 4); m = div(5c + 456, 153)
23✔
23
    return m > 12 ? m - 12 : m
23✔
24
end
25
function monthday(days)
×
26
    z = days + 306; h = 100z - 25; a = fld(h,3652425); b = a - fld(a,4)
×
27
    y = fld(100b + h, 36525); c = b + z - 365y - fld(y, 4); m = div(5c + 456, 153)
×
28
    d = c - div(153m - 457, 5); return m > 12 ? (m - 12, d) : (m, d)
×
29
end
30
function day(days)
23✔
31
    z = days + 306; h = 100z - 25; a = fld(h,3652425); b = a - fld(a,4)
23✔
32
    y = fld(100b + h, 36525); c = b + z - 365y - fld(y, 4); m = div(5c + 456, 153)
23✔
33
    return c - div(153m - 457, 5)
23✔
34
end
35
# https://en.wikipedia.org/wiki/Talk:ISO_week_date#Algorithms
36
const WEEK_INDEX = (15, 23, 3, 11)
37
function week(days)
×
38
    w = div(abs(days - 1), 7) % 20871
×
39
    c, w = divrem((w + (w >= 10435)), 5218)
×
40
    w = (w * 28 + WEEK_INDEX[c + 1]) % 1461
×
41
    return div(w, 28) + 1
×
42
end
43

44
function quarter(days)
×
45
    m = month(days)
×
46
    return m < 4 ? 1 : m < 7 ? 2 : m < 10 ? 3 : 4
×
47
end
48

49

50
# Accessor functions
51
value(dt::TimeType) = dt.instant.periods.value
166✔
52
value(t::Time) = t.instant.value
×
53
days(dt::Date) = value(dt)
×
54
days(dt::DateTime) = fld(value(dt), 86400000)
69✔
55
year(dt::TimeType) = year(days(dt))
23✔
56
quarter(dt::TimeType) = quarter(days(dt))
×
57
month(dt::TimeType) = month(days(dt))
23✔
58
week(dt::TimeType) = week(days(dt))
×
59
day(dt::TimeType) = day(days(dt))
23✔
60
hour(dt::DateTime)   = mod(fld(value(dt), 3600000), 24)
23✔
61
minute(dt::DateTime) = mod(fld(value(dt), 60000), 60)
23✔
62
second(dt::DateTime) = mod(fld(value(dt), 1000), 60)
23✔
63
millisecond(dt::DateTime) = mod(value(dt), 1000)
25✔
64
hour(t::Time)   = mod(fld(value(t), 3600000000000), Int64(24))
×
65
minute(t::Time) = mod(fld(value(t), 60000000000), Int64(60))
×
66
second(t::Time) = mod(fld(value(t), 1000000000), Int64(60))
×
67
millisecond(t::Time) = mod(fld(value(t), Int64(1000000)), Int64(1000))
×
68
microsecond(t::Time) = mod(fld(value(t), Int64(1000)), Int64(1000))
×
69
nanosecond(t::Time) = mod(value(t), Int64(1000))
×
70

71
dayofmonth(dt::TimeType) = day(dt)
×
72

73
yearmonth(dt::TimeType) = yearmonth(days(dt))
×
74
monthday(dt::TimeType) = monthday(days(dt))
×
75
yearmonthday(dt::TimeType) = yearmonthday(days(dt))
×
76

77
# Documentation for exported accessors
78
for func in (:year, :month, :quarter)
79
    name = string(func)
80
    @eval begin
81
        @doc """
82
            $($name)(dt::TimeType)::Int64
83

84
        The $($name) of a `Date` or `DateTime` as an [`Int64`](@ref).
85
        """ $func(dt::TimeType)
86
    end
87
end
88

89
"""
90
    week(dt::TimeType)::Int64
91

92
Return the [ISO week date](https://en.wikipedia.org/wiki/ISO_week_date) of a `Date` or
93
`DateTime` as an [`Int64`](@ref). Note that the first week of a year is the week that
94
contains the first Thursday of the year, which can result in dates prior to January 4th
95
being in the last week of the previous year. For example, `week(Date(2005, 1, 1))` is the 53rd
96
week of 2004.
97

98
# Examples
99
```jldoctest
100
julia> week(Date(1989, 6, 22))
101
25
102

103
julia> week(Date(2005, 1, 1))
104
53
105

106
julia> week(Date(2004, 12, 31))
107
53
108
```
109
"""
110
week(dt::TimeType)
111

112
for func in (:day, :dayofmonth)
113
    name = string(func)
114
    @eval begin
115
        @doc """
116
            $($name)(dt::TimeType)::Int64
117

118
        The day of month of a `Date` or `DateTime` as an [`Int64`](@ref).
119
        """ $func(dt::TimeType)
120
    end
121
end
122

123
"""
124
    hour(dt::DateTime)::Int64
125

126
The hour of day of a `DateTime` as an [`Int64`](@ref).
127
"""
128
hour(dt::DateTime)
129

130
for func in (:minute, :second, :millisecond)
131
    name = string(func)
132
    @eval begin
133
        @doc """
134
            $($name)(dt::DateTime)::Int64
135

136
        The $($name) of a `DateTime` as an [`Int64`](@ref).
137
        """ $func(dt::DateTime)
138
    end
139
end
140

141
for parts in (["year", "month"], ["month", "day"], ["year", "month", "day"])
142
    name = join(parts)
143
    func = Symbol(name)
144
    @eval begin
145
        @doc """
146
            $($name)(dt::TimeType) -> ($(join(repeated(Int64, length($parts)), ", ")))
147

148
        Simultaneously return the $(join($parts, ", ", " and ")) parts of a `Date` or
149
        `DateTime`.
150
        """ $func(dt::TimeType)
151
    end
152
end
153

154
for func in (:hour, :minute, :second, :millisecond, :microsecond, :nanosecond)
155
    name = string(func)
156
    @eval begin
157
        @doc """
158
            $($name)(t::Time)::Int64
159

160
        The $($name) of a `Time` as an [`Int64`](@ref).
161
        """ $func(t::Time)
162
    end
163
end
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc