New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add DateTime.UnixEpoch and DateTimeOffset.UnixEpoch fields #23747
Comments
:winces:
|
@Clockwork-Muse I think we already have this problem with DateTime and that is why we are encouraging people to be careful when using it or just use DateTimeOffset. I am not seeing the proposal will make the situation worse. whoever going to use UnixEpoch are the people who really are doing Do you think having UTC in the name can help a little with the issue you are mentioned? or renaming the property to something more descriptive can help? |
It would be redundant because there's no such thing as a local time Unix epoch. That would fit better in intellisense docs, wouldn't it? |
@jnm2 I agree with you. I am thinking how we can mitigate @Clockwork-Muse concern or at least help people not to run into such problem. |
@jnm2 - I agree with you, the Unix epoch is an absolute stamp, so adding "Utc" would be redundant. @tarekgh - my preferred solution would be getting an all-up new date/time library, as has been previously discussed. Barring that, I'd put it on |
This is not true. the ticks inside the DateTime still corresponds to UTC. The problem you raised is only happening if you have an operation that mixes different DateTimeKind.
I am not seeing hurting adding the property to DateTime too. people who want to use that can still run to the exact same problem you mentioned. my preference here is to have the property on DateTime too. |
Sorry, when I said "local", I didn't mean
....because the ticks in And there's another thing: Ticks have nothing to do with UTC. Ticks represent an offset from an epoch (what is unimportant), and represent an absolute stamp... or are supposed to. The common credo is that they're offsets from UTC, but that doesn't actually matter: If I chose |
Thanks @Clockwork-Muse for the clarification. |
Tell them a tick is 919.263177 periods of the radiation corresponding to the transition between the two hyperfine levels of the ground state of the cesium 133 atom. Though presumably the aliens would be so far away that time dilation comes into play and tracking time would become more complex yet. (@jskeet better get Noda Time ready for intergalactic calendars? 😃) |
I am perfectly happy with this proposal. |
Me too. I dread to think about how many places I've written that code myself :( |
Maybe naive question, but why is it called |
Thanks! Updated top post with the link. |
Looks good as proposed. We may want to add the |
FYI: The API review discussion was recorded - see https://youtu.be/BEBq3__WfDc?t=2343 (13 min duration) |
I can take this and work 10/21-10/22. I'll yield to any first time contributor. |
@terrajobst the addition of the |
@adriangodong thanks for willing doing this. Let me know if there is anything I can help you with. |
I spoke with @tarekgh and the problem of From that reason I agree that leaving the substraction as manual operation is probably best. We should not add the |
That is incorrect.
That is also incorrect. The documentation describes this correctly, which is as follows: For
For
Not exactly true. |
Some clarifications as it looks there were some confusions:
To summarize, what Karel listed still hold as reasons we need to avoid exposing ToUnix/FromUnix functionality on DateTime. |
How is making a built-in of DateTime dt = unixepoch.AddSeconds(myUnixTimestamp);
DateTime eastern = TimeZoneInfo.ConvertTimeBySystemTimeZoneId(dt, "Eastern Standard Time"); This works as expected when Having a built-in As I pointed out in #17213, the behavior of |
Nobody said that. everyone agree it is useful to have it. This is why it is approved by the design committee. Karel and myself's comments were regarding the request exposing ToUnixXxx and FromUnixXxx on DateTime. Anyway, I think we all agree on:
|
Ok. Then lets move the rest of the discussion over to #17213, or open a new one if you think it's appropriate. Thanks for clarification. |
I've done an initial scan, so changes needed are:
Are these changes correct? |
And tests. Otherwise it sounds reasonable. |
Note that after you get the change to coreclr repo, it should get merged to corert repo too https://github.com/dotnet/corert/tree/master/src/System.Private.CoreLib/shared/System. so the changes need to be done in corefx repo should wait for the packages of coreclr and corert be built and merged to corefx first. |
If it's alright with @adriangodong I'd like to take this on, though I'm unsure of how to get the coreclr changes merged to the corert repo as @tarekgh has mentioned. |
@TylerBrinkley when you change anything in coreclr repo under the shared folder (e.g. https://github.com/dotnet/coreclr/tree/master/src/mscorlib/shared/System) it'll get automatically open a PR in corert repo to mirror the changes. so basically no other work need to be done more than ensuring the changes are merged and the packages (of coreclr and corert) are built and referenced in corefx. we can help you with that as needed. |
CC @safern who monitor the change monitoring between coreclr and corert |
You can unassign me as @adriangodong already submitted a PR for the coreclr changes, he just never linked it back to this proposal. |
@adriangodong did you have a chance to enable the added APIs in corefx repo? |
Can we add the netfx-port-consider label to this issue? |
The added APIs should be included in the next wave of creating the new netsatndard version and support it on the full framework. |
Occasionally I come across a point in my code where it'd be useful to have a
DateTime.UnixEpoch
field as opposed to specifying my own withnew DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)
. Usually this is when I'm calculating expiration dates for web tokens where the expiration property is the number of seconds since the Unix epoch (see https://en.wikipedia.org/wiki/Unix_time for definition).Proposed API
Example Usage
The text was updated successfully, but these errors were encountered: