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

JuliaLang / julia / #37477

pending completion
#37477

push

local

web-flow
Allow external lattice elements to properly union split (#49030)

Currently `MustAlias` is the only lattice element that is allowed
to widen to union types. However, there are others in external
packages. Expand the support we have for this in order to allow
union splitting of lattice elements.

Co-authored-by: Shuhei Kadowaki <40514306+aviatesk@users.noreply.github.com>

26 of 26 new or added lines in 5 files covered. (100.0%)

71476 of 82705 relevant lines covered (86.42%)

34756248.54 hits per line

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

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

3
# Conversion/Promotion
4

5
"""
6
    Date(dt::DateTime) -> Date
7

8
Convert a `DateTime` to a `Date`. The hour, minute, second, and millisecond parts of
9
the `DateTime` are truncated, so only the year, month and day parts are used in
10
construction.
11
"""
12
Date(dt::TimeType) = convert(Date, dt)
205✔
13

14
"""
15
    DateTime(dt::Date) -> DateTime
16

17
Convert a `Date` to a `DateTime`. The hour, minute, second, and millisecond parts of
18
the new `DateTime` are assumed to be zero.
19
"""
20
DateTime(dt::TimeType) = convert(DateTime, dt)
67✔
21

22
"""
23
    Time(dt::DateTime) -> Time
24

25
Convert a `DateTime` to a `Time`. The hour, minute, second, and millisecond parts of
26
the `DateTime` are used to create the new `Time`. Microsecond and nanoseconds are zero by default.
27
"""
28
Time(dt::DateTime) = convert(Time, dt)
×
29

30
Base.convert(::Type{DateTime}, dt::Date) = DateTime(UTM(value(dt) * 86400000))
80✔
31
Base.convert(::Type{Date}, dt::DateTime) = Date(UTD(days(dt)))
186✔
32
Base.convert(::Type{Time}, dt::DateTime) = Time(Nanosecond((value(dt) % 86400000) * 1000000))
×
33

34
Base.convert(::Type{DateTime},x::Millisecond)  = DateTime(Dates.UTInstant(x))  # Converts Rata Die milliseconds to a DateTime
×
35
Base.convert(::Type{Millisecond},dt::DateTime) = Millisecond(value(dt))        # Converts DateTime to Rata Die milliseconds
×
36
Base.convert(::Type{Date},x::Day)  = Date(Dates.UTInstant(x))  # Converts Rata Die days to a Date
×
37
Base.convert(::Type{Day},dt::Date) = Day(value(dt))            # Converts Date to Rata Die days
×
38

39
### External Conversions
40
const UNIXEPOCH = value(DateTime(1970)) #Rata Die milliseconds for 1970-01-01T00:00:00
41

42
"""
43
    unix2datetime(x) -> DateTime
44

45
Take the number of seconds since unix epoch `1970-01-01T00:00:00` and convert to the
46
corresponding `DateTime`.
47
"""
48
function unix2datetime(x)
3✔
49
    rata = UNIXEPOCH + round(Int64, Int64(1000) * x)
3✔
50
    return DateTime(UTM(rata))
3✔
51
end
52
"""
53
    datetime2unix(dt::DateTime) -> Float64
54

55
Take the given `DateTime` and return the number of seconds
56
since the unix epoch `1970-01-01T00:00:00` as a [`Float64`](@ref).
57
"""
58
datetime2unix(dt::DateTime) = (value(dt) - UNIXEPOCH) / 1000.0
×
59

60
"""
61
    now() -> DateTime
62

63
Return a `DateTime` corresponding to the user's system time including the system timezone
64
locale.
65
"""
66
function now()
478✔
67
    tv = Libc.TimeVal()
478✔
68
    tm = Libc.TmStruct(tv.sec)
478✔
69
    return DateTime(tm.year + 1900, tm.month + 1, tm.mday, tm.hour, tm.min, tm.sec, div(tv.usec, 1000))
478✔
70
end
71

72
"""
73
    today() -> Date
74

75
Return the date portion of `now()`.
76
"""
77
today() = Date(now())
×
78

79
"""
80
    now(::Type{UTC}) -> DateTime
81

82
Return a `DateTime` corresponding to the user's system time as UTC/GMT.
83
For other time zones, see the TimeZones.jl package.
84

85
# Example
86
```julia
87
julia> now(UTC)
88
2023-01-04T10:52:24.864
89
```
90
"""
91
now(::Type{UTC}) = unix2datetime(time())
3✔
92

93
"""
94
    rata2datetime(days) -> DateTime
95

96
Take the number of Rata Die days since epoch `0000-12-31T00:00:00` and return the
97
corresponding `DateTime`.
98
"""
99
rata2datetime(days) = DateTime(yearmonthday(days)...)
×
100

101
"""
102
    datetime2rata(dt::TimeType) -> Int64
103

104
Return the number of Rata Die days since epoch from the given `Date` or `DateTime`.
105
"""
106
datetime2rata(dt::TimeType) = days(dt)
×
107

108
# Julian conversions
109
const JULIANEPOCH = value(DateTime(-4713, 11, 24, 12))
110

111
"""
112
    julian2datetime(julian_days) -> DateTime
113

114
Take the number of Julian calendar days since epoch `-4713-11-24T12:00:00` and return the
115
corresponding `DateTime`.
116
"""
117
function julian2datetime(f)
×
118
    rata = JULIANEPOCH + round(Int64, Int64(86400000) * f)
×
119
    return DateTime(UTM(rata))
×
120
end
121

122
"""
123
    datetime2julian(dt::DateTime) -> Float64
124

125
Take the given `DateTime` and return the number of Julian calendar days since the julian
126
epoch `-4713-11-24T12:00:00` as a [`Float64`](@ref).
127
"""
128
datetime2julian(dt::DateTime) = (value(dt) - JULIANEPOCH) / 86400000.0
×
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