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

Giorgi / DuckDB.NET / 21786556530

07 Feb 2026 08:39PM UTC coverage: 89.155% (-0.07%) from 89.223%
21786556530

push

github

Giorgi
Added support for clearing in-progress adapter

Requires DuckDB 1.5

1199 of 1393 branches covered (86.07%)

Branch coverage included in aggregate %.

6 of 8 new or added lines in 1 file covered. (75.0%)

193 existing lines in 43 files now uncovered.

2336 of 2572 relevant lines covered (90.82%)

557295.56 hits per line

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

95.0
/DuckDB.NET.Bindings/DuckDBInterval.cs
1
using System.Diagnostics.CodeAnalysis;
2

3
namespace DuckDB.NET.Native;
4

5
[StructLayout(LayoutKind.Sequential)]
6
public readonly struct DuckDBInterval(int months, int days, ulong micros)
7
{
8
    private const ulong MillisecondsByDay = (ulong)(24 * 60 * 60 * 1e6);
9
    public int Months { get; } = months;
1,503,302✔
10

11
    public int Days { get; } = days;
1,503,320✔
12
    public ulong Micros { get; } = micros;
2,255,013✔
13

14
    public static explicit operator TimeSpan(DuckDBInterval interval)
15
    {
16
        var (timeSpan, exception) = ToTimeSpan(interval);
751,636✔
17
        return timeSpan ?? throw exception!;
751,636✔
18
    }
19
    public static implicit operator DuckDBInterval(TimeSpan timeSpan) => FromTimeSpan(timeSpan);
751,591✔
20

21
    public bool TryConvert([NotNullWhen(true)] out TimeSpan? timeSpan)
22
    {
23
        (timeSpan, var exception) = ToTimeSpan(this);
33✔
24
        return exception is null;
33✔
25
    }
26

27
    private static (TimeSpan?, Exception?) ToTimeSpan(DuckDBInterval interval)
28
    {
29
        if (interval.Months > 0)
751,669✔
30
        {
31
            return (null, new ArgumentOutOfRangeException(nameof(interval), $"Cannot convert a value of type {nameof(DuckDBInterval)} to type {nameof(TimeSpan)} when the attribute 'Months' is greater or equal to 1"));
9✔
32
        }
33

34
        var days = 0;
751,660✔
35
        var micros = interval.Micros;
751,660✔
36

37
        if (interval.Micros >= MillisecondsByDay)
751,660✔
38
        {
39
            days = Convert.ToInt32(Math.Floor((double)(interval.Micros / MillisecondsByDay)));
33✔
40
            if (days > int.MaxValue - interval.Days)
33✔
41
            {
42
                return (null, new ArgumentOutOfRangeException(nameof(interval), $"Cannot convert a value of type {nameof(DuckDBInterval)} to type {nameof(TimeSpan)} when the total days value is larger than {int.MaxValue}"));
6✔
43
            }
44

45
            if (days > 0)
27✔
46
            {
47
                micros = interval.Micros - ((ulong)days * MillisecondsByDay);
27✔
48
            }
49
            days = interval.Days + days;
27✔
50
        }
51
        else
52
        {
53
            days = interval.Days;
751,627✔
54
        }
55

56
        if (micros * 10 > long.MaxValue)
751,654!
57
        {
UNCOV
58
            return (null, new ArgumentOutOfRangeException(nameof(interval), $"Cannot convert a value of type {nameof(DuckDBInterval)} to type {nameof(TimeSpan)} when the value of microseconds is larger than {long.MaxValue / 10}"));
×
59
        }
60

61
        if ((ulong)days * MillisecondsByDay * 100 + micros * 10 > long.MaxValue)
751,654✔
62
        {
63
            return (null, new ArgumentOutOfRangeException(nameof(interval), $"Cannot convert a value of type {nameof(DuckDBInterval)} to type {nameof(TimeSpan)} when the value of total microseconds is larger than {long.MaxValue}"));
6✔
64
        }
65

66
        return (new TimeSpan(days, 0, 0, 0) + new TimeSpan((long)micros * 10), null);
751,648✔
67
    }
68

69
    private static DuckDBInterval FromTimeSpan(TimeSpan timeSpan)
70
        => new(0, timeSpan.Days, Convert.ToUInt64(timeSpan.Ticks / 10 - new TimeSpan(timeSpan.Days, 0, 0, 0).Ticks / 10));
751,591✔
71
}
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