[libc-commits] [libc] [libc] Implement strftime (PR #111305)
Tsz Chan via libc-commits
libc-commits at lists.llvm.org
Wed Jan 8 22:53:23 PST 2025
tszhin-swe wrote:
Sorry I missed that, I would make sure to be clear about licensing issues
before making other PRs.
On Thu, 9 Jan 2025 at 7:26 AM, Michael Jones ***@***.***>
wrote:
> ***@***.**** commented on this pull request.
> ------------------------------
>
> In libc/src/time/strftime_core/num_converter.h
> <https://github.com/llvm/llvm-project/pull/111305#discussion_r1907948397>:
>
> > +LIBC_INLINE bool is_leap(int year) {
> + return ((year % 4 == 0) && (year % 100 != 0 || year % 400 == 0));
> +}
> +
> +static int iso_week_days(int yday, int wday) {
> + /* Add enough to the first operand of % to make it nonnegative. */
> + int big_enough_multiple_of_7 = (-YDAY_MINIMUM / 7 + 2) * 7;
> + return (yday - (yday - wday + ISO_WEEK1_WDAY + big_enough_multiple_of_7) % 7 +
> + ISO_WEEK1_WDAY - ISO_WEEK_START_WDAY);
> +}
> +
> +enum class IsoData {
> + GET_DATE,
> + GET_YEAR,
> +};
> +
> +template <IsoData get_date_or_year>
> +LIBC_INLINE int convert_iso(const FormatSection &to_conv) {
> + int year = to_conv.time->tm_year + YEAR_BASE;
> + int days = iso_week_days(to_conv.time->tm_yday, to_conv.time->tm_wday);
> +
> + if (days < 0) {
> + /* This ISO week belongs to the previous year. */
> + year--;
> + days = iso_week_days(to_conv.time->
>
> tm_yday + (365 + is_leap(year)),
> + to_conv.time->tm_wday);
> + } else {
> + int d = iso_week_days(to_conv.time->tm_yday - (365 + is_leap(year)),
> + to_conv.time->tm_wday);
> + if (0 <= d) {
> + /* This ISO week belongs to the next year. */
> + year++;
> + days = d;
> + }
> + }
>
> This section of code is copied from glibc:
> https://github.com/bminor/glibc/blob/master/time/strftime_l.c#L383
>
> That's not acceptable both for licensing and for plagiarism reasons.
> Copying code from other projects - even open source ones - can cause
> significant legal issues. The license glibc uses is called the "LGPL" and
> the license LLVM uses is based on the "Apache License". I'd recommend at
> least researching both of these before making any more PRs.
>
> —
> Reply to this email directly, view it on GitHub
> <https://github.com/llvm/llvm-project/pull/111305#pullrequestreview-2538427809>,
> or unsubscribe
> <https://github.com/notifications/unsubscribe-auth/BJM5SASTSKNAK5FBON6FOQ32JWX2HAVCNFSM6AAAAABPOP7M7OVHI2DSMVQWIX3LMV43YUDVNRWFEZLROVSXG5CSMV3GSZLXHMZDKMZYGQZDOOBQHE>
> .
> You are receiving this because you authored the thread.Message ID:
> ***@***.***>
>
https://github.com/llvm/llvm-project/pull/111305
More information about the libc-commits
mailing list