Skip to content

std.datetime: Construct struct timespec using named arguments #10838

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ibuclaw
Copy link
Member

@ibuclaw ibuclaw commented Aug 3, 2025

It is not guaranteed that the fields of the struct are in the assumed order, for example, Musl. See dlang/dmd#21249.

It is not guaranteed that the fields of the struct are in the assumed
order, for example, Musl. See dlang/dmd#21249.
@ibuclaw ibuclaw requested a review from jmdavis as a code owner August 3, 2025 14:39
@dlang-bot
Copy link
Contributor

Thanks for your pull request, @ibuclaw!

Bugzilla references

Your PR doesn't reference any Bugzilla issue.

If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog.

Testing this PR locally

If you don't have a local development environment setup, you can use Digger to test this PR:

dub run digger -- build "master + phobos#10838"

@ibuclaw
Copy link
Member Author

ibuclaw commented Aug 3, 2025

This is one of those funny cases where bitfields would actually be useful. 😬

dlang/dmd#21625

Since that'd allow the pad fields of timespec to be nameless, and - like C - timespec(1, 2) with preview=bitfields doesn't initialize unnamed fields.

Comment on lines +2629 to +2631
assert(SysTime(DateTime(1970, 1, 1, 0, 0, 1), hnsecs(9), UTC()).toTimeSpec() == timespec(tv_sec: 1, tv_nsec: 900));
assert(SysTime(DateTime(1970, 1, 1, 0, 0, 1), hnsecs(10), UTC()).toTimeSpec() == timespec(tv_sec: 1, tv_nsec: 1000));
assert(SysTime(DateTime(1970, 1, 1, 0, 0, 1), usecs(7), UTC()).toTimeSpec() == timespec(tv_sec: 1, tv_nsec: 7000));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

std/datetime/systime.d(2629:120)[warn]: Line is longer than 120 characters
std/datetime/systime.d(2630:120)[warn]: Line is longer than 120 characters
std/datetime/systime.d(2631:120)[warn]: Line is longer than 120 characters

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants