Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Subgraph: Modified basin daily snapshot to trigger at 9 am PT/12pm EST #814

Merged
merged 4 commits into from
May 21, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion projects/subgraph-basin/src/utils/Well.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,9 @@ export function incrementWellWithdraw(wellAddress: Address): void {

export function checkForSnapshot(wellAddress: Address, timestamp: BigInt, blockNumber: BigInt): void {
// We check for the prior period snapshot and then take one if needed
let dayID = dayFromTimestamp(timestamp) - 1;
// Schedule the "day" to begin at 9am PT/12pm ET.
// Future work could include properly adjusting this when DST occurs.
let dayID = dayFromTimestamp(timestamp, 8 * 60 * 60) - 1;
soilking marked this conversation as resolved.
Show resolved Hide resolved
let hourID = hourFromTimestamp(timestamp) - 1;

let well = loadWell(wellAddress);
Expand Down
11 changes: 9 additions & 2 deletions projects/subgraph-core/utils/Dates.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
import { BigInt } from "@graphprotocol/graph-ts";

export function dayFromTimestamp(timestamp: BigInt): i32 {
let day_ts = timestamp.toI32() - (timestamp.toI32() % 86400);
/**
* Optionally accepts an offset, which adjusts the start of the day from UTC 00:00.
* @param timestamp - the timestamp to extract the day from
* @param offset - how much sooner the day should roll over (relative to UTC)
* for example, for PST (UTC-7), an appropriate offset would be -7 * 60 * 60.
* This would make the day roll over 7 hours later.
*/
export function dayFromTimestamp(timestamp: BigInt, offset: i32 = 0): i32 {
let day_ts = timestamp.toI32() + offset - ((timestamp.toI32() + offset) % 86400);
return day_ts / 86400;
}

Expand Down