InfiniTime icon indicating copy to clipboard operation
InfiniTime copied to clipboard

settings: use 2024 as default year

Open vladopajic opened this issue 1 year ago • 7 comments

having 2024 as default year will make it less annoying to configure year

vladopajic avatar May 28 '24 21:05 vladopajic

Build checks have not completed. Possible reasons for this are:

  1. The checks need to be approved by a maintainer
  2. The branch has conflicts
  3. The firmware build has failed

github-actions[bot] avatar May 28 '24 21:05 github-actions[bot]

One option would be using the compiler to insert the current year at time of compilation, I'm sure that's possible as the build date page in settings already exists

Edit: looks like __DATE__ + 7 works in theory? Might generate some warnings though Edit edit: atoi(__DATE__ + 7) compiles with no warnings on GCC 13 at least, but I haven't tested if it actually works correctly

mark9064 avatar Sep 28 '24 22:09 mark9064

I like the idea of using the __DATE__ macro to use the current year, but something bugs me about using atoi to do the conversion as that'll run at runtime rather than compile-time. That's why it could be fun (although completely unnecessary) to write a simple constexpr atoi-like function so that all of it can be done at compile time.

FintasticMan avatar Sep 29 '24 19:09 FintasticMan

This attempt at constexpr atoi looks pretty bleak https://stackoverflow.com/a/59537554 😅 Maybe we only need part of it though

mark9064 avatar Sep 29 '24 20:09 mark9064

constexpr int isdigit_constexpr(int c) {
    return c >= '0' && c <= '9';
}

constexpr int atoi_constexpr(char const *str) {
    int result = 0;
    while (isdigit_constexpr(*str)) {
        result = result * 10 + *str - '0';
        str++;
    }
    return result;
}

I have no idea why that implementation looks so difficult, this is all it takes. I guess it could be that this isn't standards-compliant, and in that post they were trying to be as compliant as possible.

FintasticMan avatar Sep 29 '24 20:09 FintasticMan

That looks much more reasonable and does the job here :+1:

mark9064 avatar Sep 30 '24 21:09 mark9064

@mark9064 thanks, good suggestions.

however i would not be able to make all those changes. my reasoning was to to make this PR because it is vary easy to change constant, instead of opening an issue about this.

please feel free to take over this PR or close it and make another one.

vladopajic avatar Oct 02 '24 11:10 vladopajic

With #2133 this is integrated now and can be closed

mark9064 avatar Oct 27 '24 22:10 mark9064

@vladopajic Thank you for the idea of setting the year by default! And for the initial implementation, it was very helpful for working out the final solution.

FintasticMan avatar Oct 28 '24 10:10 FintasticMan

@vladopajic Thank you for the idea of setting the year by default! And for the initial implementation, it was very helpful for working out the final solution.

🙏

kudos to you guys!

vladopajic avatar Oct 28 '24 13:10 vladopajic