bito-code-review[bot] commented on code in PR #36111: URL: https://github.com/apache/superset/pull/36111#discussion_r2526695872
########## superset-frontend/src/utils/persianCalendar.ts: ########## @@ -0,0 +1,126 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import { isValidJalaaliDate, toGregorian, toJalaali } from 'jalaali-js'; + +export interface PersianDateParts { + year: number; + month: number; + day: number; + monthName: string; + weekday: string; +} + +export interface GregorianDateParts { + year: number; + month: number; + day: number; +} + +// Persian calendar months +export const PERSIAN_MONTHS = [ + 'فروردین', + 'اردیبهشت', + 'خرداد', + 'تیر', + 'مرداد', + 'شهریور', + 'مهر', + 'آبان', + 'آذر', + 'دی', + 'بهمن', + 'اسفند', +]; + +// Persian calendar days +export const PERSIAN_WEEKDAYS = [ + 'شنبه', + 'یکشنبه', + 'دوشنبه', + 'سهشنبه', + 'چهارشنبه', + 'پنجشنبه', + 'جمعه', +]; + +const getWeekdayName = (year: number, month: number, day: number) => + PERSIAN_WEEKDAYS[new Date(year, month - 1, day).getDay()]; Review Comment: <div> <div id="suggestion"> <div id="issue"><b>Wrong Persian weekday calculation</b></div> <div id="fix"> The weekday calculation in `getWeekdayName` incorrectly maps Gregorian weekdays to Persian weekdays because the `PERSIAN_WEEKDAYS` array starts with Saturday (index 0) while JavaScript's `getDay()` starts with Sunday (index 0). This causes incorrect weekday names to be returned, affecting any code that relies on `gregorianToPersian` for accurate date information. The fix adjusts the index using `(getDay() + 1) % 7` to align the week start days properly. </div> <details> <summary> <b>Code suggestion</b> </summary> <blockquote>Check the AI-generated fix before applying</blockquote> <div id="code"> ````suggestion const getWeekdayName = (year: number, month: number, day: number) => PERSIAN_WEEKDAYS[(new Date(year, month - 1, day).getDay() + 1) % 7]; ```` </div> </details> </div> <small><i>Code Review Run <a href=https://github.com/apache/superset/pull/36111#issuecomment-3531768745>#a88474</a></i></small> </div> --- Should Bito avoid suggestions like this for future reviews? (<a href=https://alpha.bito.ai/home/ai-agents/review-rules>Manage Rules</a>) - [ ] Yes, avoid them -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
