Skip to content

Commit

Permalink
fix(stip): get current week
Browse files Browse the repository at this point in the history
  • Loading branch information
viet-nv committed Jul 16, 2024
1 parent 37f27ce commit 9985fac
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/components/Menu/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ export default function Menu() {
<MenuItem onClick={toggle}>
<NavLink to={APP_PATHS.ELASTIC_SNAPSHOT}>
<AlertOctagon size={14} />
<Trans>Snapshot</Trans>
<Trans>Treasury Grant 2023</Trans>
</NavLink>
</MenuItem>

Expand Down
14 changes: 7 additions & 7 deletions src/pages/Campaign/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,20 @@ import { StatCard, Tab, Tabs, Wrapper } from './styles'

function getCurrentWeek(): number {
const currentDate: Date = new Date()
const startOfYear: Date = new Date(currentDate.getFullYear(), 0, 1)
const startOfYear: Date = new Date(Date.UTC(currentDate.getUTCFullYear(), 0, 1))

// Calculate the day of the week for the start of the year
const dayOfWeek: number = startOfYear.getDay()
// Calculate the day of the week for the start of the year in UTC
const dayOfWeek: number = startOfYear.getUTCDay()

// Adjust the start of the year to the nearest Monday
// Adjust the start of the year to the nearest Monday in UTC
let firstMonday: Date
if (dayOfWeek <= 4) {
firstMonday = new Date(startOfYear.setDate(startOfYear.getDate() - dayOfWeek + 1))
firstMonday = new Date(startOfYear.setUTCDate(startOfYear.getUTCDate() - dayOfWeek + 1))
} else {
firstMonday = new Date(startOfYear.setDate(startOfYear.getDate() + (8 - dayOfWeek)))
firstMonday = new Date(startOfYear.setUTCDate(startOfYear.getUTCDate() + (8 - dayOfWeek)))
}

// Calculate the difference in days from the first Monday of the year
// Calculate the difference in days from the first Monday of the year in UTC
const diffInMs: number = currentDate.getTime() - firstMonday.getTime()
const diffInDays: number = Math.floor(diffInMs / (24 * 60 * 60 * 1000))

Expand Down

0 comments on commit 9985fac

Please sign in to comment.