Why weeks in solidity start on Thursday

Jun 26
10
min of reading

When we talk about rounding down timestampsto weeks in Solidity, the operation typically looks like this:

Here, block.timestamp gives the currentblock's timestamp (in seconds since the Unix Epoch), 1 week is a conveniencenotation for 604,800 seconds (the number of seconds in a week), and thedivision followed by multiplication effectively rounds down the timestamp tothe start of the current week.

This is a common pattern which is used todefine weekly epoch starts.

Now, why does this operation always end uppointing to last Thursday at 00:00 UTC?

It's a fascinating interplay between howUnix timestamps work and the weekly calendar cycle. Unix time counts theseconds since the Unix Epoch (January 1st, 1970, at 00:00 UTC), which happensto be a Thursday.

Since a week is precisely 7 days or 168hours, any whole multiple of weeks from the Unix Epoch will always fall on aThursday.

This seemingly trivial detail has practicalimplications for projects. By rounding down to the nearest week, contracts thatexecute epoch-based logic can ensure a consistent starting point for newepochs.

This consistency is crucial forapplications where events, actions, or changes must occur at regular intervals.The choice to start epochs on Thursday is not arbitrary but a direct result ofthe Unix timestamp's origin point.

For developers and projects utilizing thistechnique, it means that regardless of when an epoch-triggering transactionoccurs, the new epoch will always start on a Thursday at 00:00 UTC. Thispredictability is valuable for scheduling, forecasting, and aligning events.

Read the original article

Related articles