Skip to content

Commit f633ad6

Browse files
authored
fix: handle explicit time zones in automation (hashgraph#2504)
Signed-off-by: yasenltd <yasenltd@gmail.com>
1 parent 1c0bf9d commit f633ad6

2 files changed

Lines changed: 44 additions & 38 deletions

File tree

automation/pages/TransactionPage.ts

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -143,18 +143,6 @@ export class TransactionPage extends BasePage {
143143
draftDetailsDescriptionIndexSelector = 'span-draft-tx-description-';
144144
draftDetailsIsTemplateCheckboxSelector = 'checkbox-is-template-';
145145

146-
// Method to close the 'Save Draft' modal if it appears
147-
async closeDraftModal() {
148-
// Wait for the button to be visible with a timeout
149-
const modalButton = this.window.getByTestId(this.discardModalDraftButtonSelector);
150-
await modalButton.waitFor({ state: 'visible', timeout: 500 }).catch(() => {});
151-
152-
// If the modal is visible, then click the button to close the modal
153-
if (await modalButton.isVisible()) {
154-
await modalButton.click();
155-
}
156-
}
157-
158146
// Combined method to verify all elements on Create transaction page
159147
async verifyAccountCreateTransactionElements() {
160148
const checks = await Promise.all([

automation/utils/util.ts

Lines changed: 44 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -201,44 +201,62 @@ export function calculateTimeout(totalUsers: number, timePerUser: number): numbe
201201
}
202202

203203
/**
204-
* Waits for a valid start time to continue the test.
205-
* @param dateTimeString - The target date and time in string format.
206-
* @param bufferSeconds - The buffer time in seconds to wait before the target time.
207-
* @returns {Promise<void>} - A promise that resolves after the wait time.
204+
* Waits until a transaction start time becomes valid.
205+
* Supports both Hedera UI format and ISO date formats.
206+
*
207+
* Examples supported:
208+
* - "Wed, Feb 04, 2026 16:05:05 UTC"
209+
* - "2026-02-04T16:05:05"
210+
* - "2026-02-04T16:05:05Z"
211+
*
212+
* @param dateTimeString - The target date/time string.
213+
* @param bufferSeconds - Additional seconds to wait before execution.
208214
*/
209-
export async function waitForValidStart(dateTimeString: string, bufferSeconds = 15): Promise<void> {
210-
// Convert the dateTimeString to a Date object
211-
// Handle both "Wed, Feb 04, 2026 16:05:05 UTC" and ISO formats
212-
let dateStr = dateTimeString;
213-
if (dateStr.endsWith(' UTC')) {
214-
// Replace " UTC" with " GMT" - JS Date understands GMT as UTC timezone
215-
dateStr = dateStr.replace(' UTC', ' GMT');
216-
} else if (!dateStr.endsWith('Z')) {
217-
// Add Z suffix for ISO format strings that don't have timezone
218-
dateStr = dateStr + 'Z';
215+
export async function waitForValidStart(
216+
dateTimeString: string,
217+
bufferSeconds: number = 15,
218+
): Promise<void> {
219+
if (!dateTimeString || !dateTimeString.trim()) {
220+
console.log('waitForValidStart: start time is empty. Skipping wait.');
221+
return;
222+
}
223+
224+
let normalizedDate = dateTimeString.trim();
225+
226+
// Handle Hedera UI format: "Wed, Feb 04, 2026 16:05:05 UTC"
227+
if (normalizedDate.endsWith(' UTC')) {
228+
normalizedDate = normalizedDate.replace(' UTC', ' GMT');
219229
}
220-
const targetDate = new Date(dateStr);
230+
231+
// Handle ISO strings missing timezone
232+
if (
233+
!normalizedDate.endsWith('Z') &&
234+
!normalizedDate.includes('GMT') &&
235+
!normalizedDate.includes('+')
236+
) {
237+
normalizedDate = `${normalizedDate}Z`;
238+
}
239+
240+
const targetDate = new Date(normalizedDate);
241+
221242
if (isNaN(targetDate.getTime())) {
222243
throw new Error(
223-
`waitForValidStart: invalid date string. Original: "${dateTimeString}", normalized: "${dateStr}"`,
244+
`waitForValidStart: invalid date string. Original: "${dateTimeString}", normalized: "${normalizedDate}"`,
224245
);
225246
}
226247

227-
// Get the current time
228-
const currentDate = new Date();
248+
const now = new Date();
249+
const timeDifference = targetDate.getTime() - now.getTime();
229250

230-
// Calculate the difference in milliseconds
231-
const timeDifference = targetDate.getTime() - currentDate.getTime();
251+
const waitTime = Math.max(timeDifference + bufferSeconds * 1000, 0);
232252

233-
// Add buffer time (in milliseconds)
234-
const waitTime = Math.max(timeDifference + bufferSeconds * 1000, 0); // Ensure non-negative
235-
236-
// Wait for the calculated time
237253
if (waitTime > 0) {
238-
console.log(`Waiting for ${waitTime / 1000} seconds until the valid start time...`);
254+
const seconds = Math.ceil(waitTime / 1000);
255+
console.log(`Waiting ${seconds} seconds until transaction start time becomes valid...`);
256+
239257
await new Promise(resolve => setTimeout(resolve, waitTime));
240258
} else {
241-
console.log('The target time has already passed.');
259+
console.log('The target start time has already passed.');
242260
}
243261
}
244262

0 commit comments

Comments
 (0)