julia icon indicating copy to clipboard operation
julia copied to clipboard

Add replace for TimeTypes

Open omus opened this issue 7 years ago • 6 comments

Supports using Periods or Time to replace fields in a given DateTime.

Addresses part of: https://github.com/JuliaLang/julia/issues/24814

omus avatar Jan 30 '18 21:01 omus

cc: @quinnj

omus avatar Jan 30 '18 21:01 omus

Yeah, I'm inclined to think DateTime(dt::DateTime, p::Period) would be better than replace. The latter is currently only defined for collections, so that wouldn't be very logical. Any drawbacks to using the constructor instead?

nalimilan avatar Feb 05 '18 13:02 nalimilan

If dates and times used properties, you could write this as dt.minute = x.

StefanKarpinski avatar Feb 05 '18 15:02 StefanKarpinski

I'm not a fan of this, since the generic replace function takes old=>new update pairs, which this doesn't. This is more like a non-mutating update, which we do need better APIs, for, but I don't think this is it. The constructor would be reasonable.

Keno avatar Dec 25 '20 03:12 Keno

Date and time components can be set with the excellent Accessors.jl.

julia> using Dates, Accessors

julia> d = Date(2024, 12, 31)
2024-12-31

julia> @set month(d) = 1
2024-01-31

julia> t = DateTime(2024, 12, 31, 23, 59, 59)
2024-12-31T23:59:59

julia> @set minute(t) = 4
2024-12-31T23:04:59

jariji avatar Feb 14 '24 00:02 jariji

Great point about Accessors.jl, that's really nice.

My personal view would be that this alleviates the need for this PR -- I also am not happy about its use of replace.

fingolfin avatar Feb 15 '24 23:02 fingolfin