Skip to content

at(dt::DateTime, t::Time) and at(d::Date, t::Time) #24814

Open
@s-celles

Description

Hello,

Julia now have a Time type thanks to @aviks issue #12140 and @quinnj PR #12274

but a function that returns DateTime at a given Time (from either a Date or a DateTime)
could be a nice feature to have.

Usage example :
with DateTime

julia> dt = DateTime(2010, 1, 3, 20, 30)
2010-01-03T20:30:00

julia> at(dt, Dates.Time(13, 30))
2010-01-03T13:30:00

with Date

julia> d = Date(2010, 1, 1)
2010-01-03
julia> at(dt, Dates.Time(13, 30))
2010-01-03T13:30:00

This is a bit out of the scope of this issue but creating a DateTime from Date and Time is not as easy as it should be

julia> dt = DateTime(2010, 1, 3, 20, 30)
2010-01-03T20:30:00

julia> d = Date(dt)
2010-01-03

julia> t = Dates.Time(dt)
20:30:00

julia> DateTime(d, t)
ERROR: MethodError: Cannot `convert` an object of type Base.Dates.Time to an object of type Int64
This may have arisen from a call to the constructor Int64(...),
since type constructors fall back to convert methods.
Stacktrace:
 [1] DateTime(::Date, ::Base.Dates.Time) at ./dates/types.jl:311

Kind regards

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    datesDates, times, and the Dates stdlib modulestdlibJulia's standard library

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions