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

TimeStamp #1728

Open
MUR-88 opened this issue Dec 26, 2023 · 2 comments
Open

TimeStamp #1728

MUR-88 opened this issue Dec 26, 2023 · 2 comments

Comments

@MUR-88
Copy link

MUR-88 commented Dec 26, 2023

async function mySync() {
try {
await synchronize({
database,
pullChanges: async ({ schemaVersion, lastPulledAt, migration }) => {
const urlParams = last_pulled_at=${lastPulledAt}&schema_version=${schemaVersion}&migration=${encodeURIComponent( JSON.stringify(migration), )}
console.log("URL Params", urlParams);
const response = await API.get(master_sector/sync?${urlParams});
console.log(response);
// Check if the request was successful
if (response.status_code !== 200) {
throw new Error(Request failed with status ${response.status});
}
const timestamp = dayjs().unix();
console.log("timestamp", timestamp);
return { changes: response.data, timestamp: timestamp };
},

  });
} catch (error) {
  console.log("Catch Mysync",error);
}

}

the timestamp value not read properly. the value 01/jan/1970

any idea?

@garygcchiu
Copy link

garygcchiu commented Dec 30, 2023

Here's your code reformatted to make it easier for people to follow and help:

async function mySync() {
	try {
		await synchronize({
			database,
			pullChanges: async ({ schemaVersion, lastPulledAt, migration }) => {
				const urlParams = `last_pulled_at=${lastPulledAt}&schema_version=${schemaVersion}&migration=${encodeURIComponent( JSON.stringify(migration))}`
				const response = await API.get(`master_sector/sync?${urlParams}`);

				// Check if the request was successful
				if (response.status_code !== 200) {
					throw new Error(`Request failed with status ${response.status}`);
				}

				const timestamp = dayjs().unix();
				return { 
				    changes: response.data, 
				    timestamp: timestamp 
				};
			},
		});
	} catch (error) {
		console.log("Catch Mysync",error);
	}
}

Also, since you added console.log() statements to it, would you mind sharing what they output? It would also make it easier for others to follow and help.

@kulak91
Copy link
Contributor

kulak91 commented Mar 4, 2024

const timestamp = dayjs().unix(); will always return 1970 jan. You get what you set. If you need current timestamp try to think about dayjs().valueOf()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants