The sortTimestamps function is a tailored utility for sorting Firestore timestamps. It compares two timestamps and determines their chronological order, making it invaluable for organizing time-based data in Firestore.
Organizing and comparing time-based data often requires sorting timestamps. The sortTimestamps function provides a reliable and straightforward way to compare and sort Firestore timestamps, accommodating possibly missing values to ensure robust and error-free operations.
Import sortTimestamps and use it as a comparator function when sorting timestamps:
import { firestore } from 'firebase-admin'import { sortTimestamps } from 'path-to-your-utilities'// Example Firestore timestampsconst timestamp1: firestore.Timestamp = firestore.Timestamp.now()const timestamp2: firestore.Timestamp = firestore.Timestamp.fromDate( new Date('2020-01-01'),)// Comparing two timestampsconst comparisonResult = sortTimestamps(timestamp1, timestamp2)// 'comparisonResult' will be 1, -1, or 0, depending on the chronological order of the timestamps
sortTimestamps is designed to deal with missing timestamps effectively, ensuring that arrays of timestamps are sorted correctly even when some values are missing.
Integrate sortTimestamps into array sorting operations when dealing with Firestore timestamp data.
Use sortTimestamps for manual timestamp comparisons to maintain consistency and reliability in your time-based logic.
Be cautious when sorting large arrays of timestamps and consider performance implications.
When working with timestamps from various sources, consider potential
inconsistencies due to time zone differences or clock synchronization issues.
{"docsConfig":{"$schema":"https://mintlify.com/docs.json","theme":"mint","name":"Firebridge","colors":{"primary":"#36656B","light":"#DAF1F4","dark":"#36656B"},"favicon":"/favicon.svg","logo":{"light":"https://mintcdn.com/humancollective/oNaxoG7QbCmsD9Gt/logo/light.svg?fit=max\u0026auto=format\u0026n=oNaxoG7QbCmsD9Gt\u0026q=85\u0026s=19a786e3b49034489f469d223f640a91","dark":"https://mintcdn.com/humancollective/oNaxoG7QbCmsD9Gt/logo/dark.svg?fit=max\u0026auto=format\u0026n=oNaxoG7QbCmsD9Gt\u0026q=85\u0026s=5ab41e88ab90b2cf7147044fcf65c387"},"background":{"decoration":null,"color":{"light":"#f3f8f8","dark":"#1e2a2e"}},"navbar":{"primary":{"type":"button","label":"Github","href":"https://github.com/firebridgekit/Firebridge"}},"footer":{"socials":{"github":"https://github.com/firebridgekit/Firebridge"}},"navigation":{"pages":[]}},"deployment":{"deploymentMetadataValue":{"subdomain":"humancollective","hasAudioNarration":false,"actualSubdomain":"humancollective","customDomains":["firebridge.dev"],"gitSource":{"type":"github","owner":"firebridgekit","repo":"firebridge","deployBranch":"main","contentDirectory":"docs","isPrivate":false,"mountPath":"","label":""},"chroma":{"liveDeploymentHistoryId":"6a21a6025634a55fb597136b","collectionId":"35ec6246-3e30-4bc4-b309-ee939fc07198","schemaVersion":"v2"},"entitlements":{},"buildId":"6a21a6025634a55fb597136b:success","clientVersion":"0.0.4043","searchFilterCounts":[{"language":"default","tag":"Cloud","count":26},{"language":"default","tag":"Actions","count":7},{"language":"default","tag":"Timestamps","count":6},{"language":"default","tag":"Metrics","count":5},{"language":"default","tag":"React","count":4},{"language":"default","tag":"Snapshots","count":3},{"language":"default","tag":"Hooks","count":3},{"language":"default","tag":"Execution","count":2},{"language":"default","tag":"Invokeables","count":2},{"language":"default","tag":"Introduction","count":2}]},"assistantConfig":{},"basePath":"","hasChatPermissions":false,"hasWebMcpPermissions":false,"toggles":[{"name":"kill-isr","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"agent-mintlify-slack","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"agent-integrations-settings","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"automations-pr-grouping","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"custom-prefix","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"analytics-v7","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"user-flows-analytics","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"no-publish-flow","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workos-onboarding","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"llms-txt-v2","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"snapshot-serving-live","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"stripTemperatureMiddleware","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"support-platform-pylon-zendesk","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"snapshot-serving","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"instant-rollback","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"granular-notifications-server","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"granular-notifications","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"automations-fable","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"fixed-ai-action-pricing","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"automation-resolve-merge-conflict","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"scoped-publishing","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"mintql","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"page-level-analytics","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"editor-version-history-v2","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"billing-page-v2","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"full-page-search","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workspace-projects","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"assistant-v5","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"byok-sep-25","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"fork-pr-previews","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"revalidation-jwt","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"vite-origin","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"billing-updated-9-15","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workos-sso-scim","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"hobby-abuse-scan","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"dashboard-inbox","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workos-signup","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"turbopuffer-dual-write","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workos-enabled","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"approve-review-flow","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false}],"googleFontsInlined":false},"customCss":[],"page":{"pagePath":"cloud/timestamps/sortTimestamps","slug":"/cloud/timestamps/sortTimestamps","pageMetadata":{"title":"sortTimestamps","description":"The `sortTimestamps` function is a tailored utility for sorting Firestore timestamps. It compares two timestamps and determines their chronological order, making it invaluable for organizing time-based data in Firestore.","icon":"code","href":"/cloud/timestamps/sortTimestamps"},"description":{"compiledSource":"\"use strict\";\nconst {jsx: _jsx, jsxs: _jsxs} = arguments[0];\nconst {useMDXComponents: _provideComponents} = arguments[0];\nfunction _createMdxContent(props) {\n const _components = {\n code: \"code\",\n p: \"p\",\n ..._provideComponents(),\n ...props.components\n };\n return _jsxs(_components.p, {\n children: [\"The \", _jsx(_components.code, {\n children: \"sortTimestamps\"\n }), \" function is a tailored utility for sorting Firestore timestamps. It compares two timestamps and determines their chronological order, making it invaluable for organizing time-based data in Firestore.\"]\n });\n}\nfunction MDXContent(props = {}) {\n const {wrapper: MDXLayout} = {\n ..._provideComponents(),\n ...props.components\n };\n return MDXLayout ? _jsx(MDXLayout, {\n ...props,\n children: _jsx(_createMdxContent, {\n ...props\n })\n }) : _createMdxContent(props);\n}\nreturn {\n default: MDXContent\n};\n","frontmatter":{},"scope":{}},"pageType":"default","mdx":{"mdxSource":{"compiledSource":"\"use strict\";const{Fragment:_Fragment,jsx:_jsx,jsxs:_jsxs}=arguments[0];const{useMDXComponents:_provideComponents}=arguments[0];function _createMdxContent(props){const _components={code:`code`,li:`li`,p:`p`,pre:`pre`,span:`span`,strong:`strong`,ul:`ul`,..._provideComponents(),...props.components},{CodeBlock,Heading,Warning}=_components;if(!CodeBlock)_missingMdxReference(`CodeBlock`,true);if(!Heading)_missingMdxReference(`Heading`,true);if(!Warning)_missingMdxReference(`Warning`,true);return _jsxs(_Fragment,{children:[_jsx(Heading,{level:`2`,id:`introduction`,children:`Introduction`}),`\n`,_jsxs(_components.p,{children:[`Organizing and comparing time-based data often requires sorting timestamps. The `,_jsx(_components.code,{children:`sortTimestamps`}),` function provides a reliable and straightforward way to compare and sort Firestore timestamps, accommodating possibly missing values to ensure robust and error-free operations.`]}),`\n`,_jsx(Heading,{level:`3`,id:`key-features`,children:`Key Features`}),`\n`,_jsxs(_components.ul,{children:[`\n`,_jsxs(_components.li,{children:[_jsx(_components.strong,{children:`Chronological Sorting`}),`: Compares two Firestore timestamps and sorts them chronologically.`]}),`\n`,_jsxs(_components.li,{children:[_jsx(_components.strong,{children:`Handles Missing Timestamps`}),`: Gracefully manages scenarios where one or both timestamps may be missing (`,_jsx(_components.code,{children:`null`}),` or `,_jsx(_components.code,{children:`undefined`}),`).`]}),`\n`,_jsxs(_components.li,{children:[_jsx(_components.strong,{children:`Versatile Application`}),`: Ideal for use in array sorting methods or when manually comparing timestamps.`]}),`\n`]}),`\n`,_jsx(Heading,{level:`3`,id:`utilization`,children:`Utilization`}),`\n`,_jsx(Heading,{level:`4`,id:`comparing-two-timestamps`,children:`Comparing Two Timestamps`}),`\n`,_jsxs(_components.p,{children:[`Import `,_jsx(_components.code,{children:`sortTimestamps`}),` and use it as a comparator function when sorting timestamps:`]}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`13`,language:`typescript`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`typescript`,children:_jsxs(_components.code,{language:`typescript`,numberOfLines:`13`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`import`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` { `}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`firestore`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` } `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`from`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` 'firebase-admin'`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`import`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` { `}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`sortTimestamps`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` } `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`from`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` 'path-to-your-utilities'`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`// Example Firestore timestamps`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`const`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:` timestamp1`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`:`}),_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#4EC9B0`},children:` firestore`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#4EC9B0`},children:`Timestamp`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` firestore`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`Timestamp`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`now`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`()`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`const`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:` timestamp2`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`:`}),_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#4EC9B0`},children:` firestore`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#4EC9B0`},children:`Timestamp`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` firestore`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`Timestamp`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`fromDate`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` new`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` Date`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`'2020-01-01'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`),`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`)`})}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`// Comparing two timestamps`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`const`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:` comparisonResult`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` sortTimestamps`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`timestamp1`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`timestamp2`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`)`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`// 'comparisonResult' will be 1, -1, or 0, depending on the chronological order of the timestamps`})}),`\n`]})})}),`\n`,_jsx(Heading,{level:`2`,id:`handling-missing-timestamps`,children:`Handling Missing Timestamps`}),`\n`,_jsxs(_components.p,{children:[_jsx(_components.code,{children:`sortTimestamps`}),` is designed to deal with missing timestamps effectively, ensuring that arrays of timestamps are sorted correctly even when some values are missing.`]}),`\n`,_jsx(Heading,{level:`2`,id:`best-practices`,children:`Best Practices`}),`\n`,_jsxs(_components.ul,{children:[`\n`,_jsxs(_components.li,{children:[`Integrate `,_jsx(_components.code,{children:`sortTimestamps`}),` into array sorting operations when dealing with Firestore timestamp data.`]}),`\n`,_jsxs(_components.li,{children:[`Use `,_jsx(_components.code,{children:`sortTimestamps`}),` for manual timestamp comparisons to maintain consistency and reliability in your time-based logic.`]}),`\n`,_jsx(_components.li,{children:`Be cautious when sorting large arrays of timestamps and consider performance implications.`}),`\n`]}),`\n`,_jsx(Warning,{children:_jsx(_components.p,{children:`When working with timestamps from various sources, consider potential\ninconsistencies due to time zone differences or clock synchronization issues.`})})]})}function MDXContent(props={}){const{wrapper:MDXLayout}={..._provideComponents(),...props.components};return MDXLayout?_jsx(MDXLayout,{...props,children:_jsx(_createMdxContent,{...props})}):_createMdxContent(props)}return{default:MDXContent};function _missingMdxReference(id,component){throw new Error(`Expected `+(component?`component`:`object`)+\" `\"+id+\"` to be defined: you likely forgot to import, pass, or provide it.\")}","frontmatter":{},"scope":{"config":{},"pageMetadata":{"title":"sortTimestamps","description":"The `sortTimestamps` function is a tailored utility for sorting Firestore timestamps. It compares two timestamps and determines their chronological order, making it invaluable for organizing time-based data in Firestore.","icon":"code","href":"/cloud/timestamps/sortTimestamps"}}},"mdxSourceWithNoJs":null},"mdxExtracts":{"tableOfContents":[{"title":"Introduction","slug":"introduction","depth":2,"children":[{"title":"Key Features","slug":"key-features","depth":3,"children":[]},{"title":"Utilization","slug":"utilization","depth":3,"children":[]},{"title":"Comparing Two Timestamps","slug":"comparing-two-timestamps","depth":4,"children":[]}]},{"title":"Handling Missing Timestamps","slug":"handling-missing-timestamps","depth":2,"children":[]},{"title":"Best Practices","slug":"best-practices","depth":2,"children":[]}],"codeExamples":{}},"jsLinks":[],"subdomain":"humancollective","siteName":"Firebridge","title":"sortTimestamps - Firebridge","navMaps":{"firstHrefInVersion":{},"firstHrefInLanguage":{}},"lastModified":"2026-01-07T00:45:36.611Z","originalFileLocation":"cloud/timestamps/sortTimestamps.mdx"},"headHtml":"\u003cscript data-mint-head>(function(){var d=document.documentElement,p=null;if(!p){try{p=localStorage.getItem(\"isDarkMode\")}catch(e){}if(p==='true')p='dark';else if(p==='false')p='light';if(p!=='light'\u0026\u0026p!=='dark'\u0026\u0026p!=='system')p=\"system\"}var r=p==='system'?(matchMedia(\"(prefers-color-scheme: dark)\").matches?'dark':'light'):p;d.classList.remove(r==='dark'?'light':'dark');d.classList.add(r);d.setAttribute(\"data-theme-preference\",p)})();\u003c/script>\u003cmeta data-mint-head name=\"description\" content=\"The sortTimestamps function is a tailored utility for sorting Firestore timestamps. It compares two timestamps and determines their chronological order, making it invaluable for organizing time-based data in Firestore.\">\u003cmeta data-mint-head name=\"application-name\" content=\"Firebridge\">\u003cmeta data-mint-head name=\"generator\" content=\"Mintlify\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"192x192\" href=\"/mintlify-assets/_mintlify/favicons/humancollective/6f5gtnvP6iWrC6WE/_generated/favicon/android-chrome-192x192.png\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"apple-touch-icon\" type=\"image/png\" sizes=\"180x180\" href=\"/mintlify-assets/_mintlify/favicons/humancollective/6f5gtnvP6iWrC6WE/_generated/favicon/apple-touch-icon.png\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"16x16\" href=\"/mintlify-assets/_mintlify/favicons/humancollective/6f5gtnvP6iWrC6WE/_generated/favicon/favicon-16x16.png\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"32x32\" href=\"/mintlify-assets/_mintlify/favicons/humancollective/6f5gtnvP6iWrC6WE/_generated/favicon/favicon-32x32.png\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"shortcut icon\" type=\"image/x-icon\" href=\"/mintlify-assets/_mintlify/favicons/humancollective/6f5gtnvP6iWrC6WE/_generated/favicon/favicon.ico\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"192x192\" href=\"/mintlify-assets/_mintlify/favicons/humancollective/6f5gtnvP6iWrC6WE/_generated/favicon-dark/android-chrome-192x192.png\" media=\"(prefers-color-scheme: dark)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"16x16\" href=\"/mintlify-assets/_mintlify/favicons/humancollective/6f5gtnvP6iWrC6WE/_generated/favicon-dark/favicon-16x16.png\" media=\"(prefers-color-scheme: dark)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"32x32\" href=\"/mintlify-assets/_mintlify/favicons/humancollective/6f5gtnvP6iWrC6WE/_generated/favicon-dark/favicon-32x32.png\" media=\"(prefers-color-scheme: dark)\">\u003clink data-mint-head rel=\"shortcut icon\" type=\"image/x-icon\" href=\"/mintlify-assets/_mintlify/favicons/humancollective/6f5gtnvP6iWrC6WE/_generated/favicon-dark/favicon.ico\" media=\"(prefers-color-scheme: dark)\">\u003cmeta data-mint-head property=\"og:title\" content=\"sortTimestamps - Firebridge\">\u003cmeta data-mint-head property=\"og:description\" content=\"The sortTimestamps function is a tailored utility for sorting Firestore timestamps. It compares two timestamps and determines their chronological order, making it invaluable for organizing time-based data in Firestore.\">\u003cmeta data-mint-head property=\"og:site_name\" content=\"Firebridge\">\u003cmeta data-mint-head property=\"og:url\" content=\"https://firebridge.dev/cloud/timestamps/sortTimestamps\">\u003cmeta data-mint-head property=\"og:type\" content=\"website\">\u003cmeta data-mint-head property=\"og:image\" content=\"https://humancollective.mintlify.app/_mintlify/api/og/v2?division=Timestamps\u0026amp;title=sortTimestamps\u0026amp;description=The+%60sortTimestamps%60+function+is+a+tailored+utility+for+sorting+Firestore+timestamps.+It+compares+two+timestamps+and+determines+their+chronological+order%2C+makin\u0026amp;theme=494a5b55d5af8e2e45aa7d13\u0026amp;signature=a9115b7f7f7d86abb484a0d8b815ced4fe0d90769f01736939831405d01edcdf\">\u003cmeta data-mint-head property=\"og:image:width\" content=\"1200\">\u003cmeta data-mint-head property=\"og:image:height\" content=\"630\">\u003cmeta data-mint-head name=\"twitter:card\" content=\"summary_large_image\">\u003cmeta data-mint-head name=\"twitter:title\" content=\"sortTimestamps - Firebridge\">\u003cmeta data-mint-head name=\"twitter:description\" content=\"The sortTimestamps function is a tailored utility for sorting Firestore timestamps. It compares two timestamps and determines their chronological order, making it invaluable for organizing time-based data in Firestore.\">\u003cmeta data-mint-head name=\"twitter:image\" content=\"https://humancollective.mintlify.app/_mintlify/api/og/v2?division=Timestamps\u0026amp;title=sortTimestamps\u0026amp;description=The+%60sortTimestamps%60+function+is+a+tailored+utility+for+sorting+Firestore+timestamps.+It+compares+two+timestamps+and+determines+their+chronological+order%2C+makin\u0026amp;theme=494a5b55d5af8e2e45aa7d13\u0026amp;signature=a9115b7f7f7d86abb484a0d8b815ced4fe0d90769f01736939831405d01edcdf\">\u003cmeta data-mint-head name=\"twitter:image:width\" content=\"1200\">\u003cmeta data-mint-head name=\"twitter:image:height\" content=\"630\">\u003cmeta data-mint-head name=\"msapplication-config\" content=\"/mintlify-assets/_mintlify/favicons/humancollective/6f5gtnvP6iWrC6WE/_generated/favicon/browserconfig.xml\">\u003cmeta data-mint-head name=\"apple-mobile-web-app-title\" content=\"Firebridge\">\u003cmeta data-mint-head name=\"msapplication-TileColor\" content=\"#36656B\">\u003clink data-mint-head rel=\"canonical\" href=\"https://firebridge.dev/cloud/timestamps/sortTimestamps\">\u003clink data-mint-head rel=\"alternate\" type=\"application/xml\" href=\"/sitemap.xml\">\u003clink data-mint-head rel=\"alternate\" type=\"text/markdown\" href=\"/cloud/timestamps/sortTimestamps.md\">\u003cscript data-mint-head type=\"application/ld+json\">{\"@context\":\"https://schema.org\",\"@graph\":[{\"@type\":\"Organization\",\"@id\":\"https://firebridge.dev/#organization\",\"name\":\"Firebridge\",\"url\":\"https://firebridge.dev\",\"logo\":{\"@type\":\"ImageObject\",\"url\":\"https://mintcdn.com/humancollective/oNaxoG7QbCmsD9Gt/logo/light.svg?fit=max\u0026auto=format\u0026n=oNaxoG7QbCmsD9Gt\u0026q=85\u0026s=19a786e3b49034489f469d223f640a91\"}},{\"@type\":\"WebSite\",\"@id\":\"https://firebridge.dev#website\",\"name\":\"Firebridge\",\"url\":\"https://firebridge.dev\",\"publisher\":{\"@id\":\"https://firebridge.dev/#organization\"}},{\"@type\":\"WebPage\",\"@id\":\"https://firebridge.dev/cloud/timestamps/sortTimestamps#webpage\",\"url\":\"https://firebridge.dev/cloud/timestamps/sortTimestamps\",\"name\":\"sortTimestamps\",\"description\":\"The sortTimestamps function is a tailored utility for sorting Firestore timestamps. It compares two timestamps and determines their chronological order, making it invaluable for organizing time-based data in Firestore.\",\"dateModified\":\"2026-01-07T00:45:36.611Z\",\"isPartOf\":{\"@id\":\"https://firebridge.dev#website\"},\"breadcrumb\":{\"@id\":\"https://firebridge.dev/cloud/timestamps/sortTimestamps#breadcrumb\"}},{\"@type\":\"BreadcrumbList\",\"@id\":\"https://firebridge.dev/cloud/timestamps/sortTimestamps#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Cloud\",\"item\":\"https://firebridge.dev/cloud/cloud-installation\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Timestamps\",\"item\":\"https://firebridge.dev/cloud/timestamps/maxTimestamp\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"sortTimestamps\",\"item\":\"https://firebridge.dev/cloud/timestamps/sortTimestamps\"}]},{\"@type\":[\"Article\",\"TechArticle\"],\"@id\":\"https://firebridge.dev/cloud/timestamps/sortTimestamps#article\",\"headline\":\"sortTimestamps\",\"name\":\"sortTimestamps\",\"description\":\"The sortTimestamps function is a tailored utility for sorting Firestore timestamps. It compares two timestamps and determines their chronological order, making it invaluable for organizing time-based data in Firestore.\",\"url\":\"https://firebridge.dev/cloud/timestamps/sortTimestamps\",\"mainEntityOfPage\":{\"@id\":\"https://firebridge.dev/cloud/timestamps/sortTimestamps#webpage\"},\"dateModified\":\"2026-01-07T00:45:36.611Z\",\"publisher\":{\"@id\":\"https://firebridge.dev/#organization\"},\"isPartOf\":{\"@id\":\"https://firebridge.dev#website\"}}]}\u003c/script>\u003cscript data-mint-head type=\"application/ld+json\">{\"@context\":\"https://schema.org\",\"@type\":\"WebSite\",\"name\":\"Firebridge\",\"creator\":{\"@type\":\"Organization\",\"name\":\"Mintlify\",\"url\":\"https://mintlify.com\"}}\u003c/script>","siteName":"Firebridge","nav":{"global":null,"groups":[{"group":"Introduction","pages":[{"title":"Why Firebridge?","href":"/introduction"},{"title":"Get Started","href":"/get-started"}]},{"group":"React","pages":[{"title":"React Installation","icon":"react","href":"/react/react-installation"},{"group":"Hooks","pages":[{"title":"useDocument","icon":"code","href":"/react/hooks/useDocument"},{"title":"useCollection","icon":"code","href":"/react/hooks/useCollection"},{"title":"useCallable","icon":"code","href":"/react/hooks/useCallable"}]}]},{"group":"Cloud","pages":[{"title":"Cloud Installation","icon":"cloud","href":"/cloud/cloud-installation"},{"group":"Invokeables","pages":[{"title":"Callables","icon":"code","href":"/cloud/invokeables/callable"},{"title":"Requestables","icon":"code","href":"/cloud/invokeables/requestable"}]},{"group":"Execution","pages":[{"title":"Batch Execution","icon":"code","href":"/cloud/execution/batch"},{"title":"Parallel Execution","icon":"code","href":"/cloud/execution/parallel"}]},{"group":"Actions","pages":[{"title":"Actions Overview","href":"/cloud/actions/actions-overview"},{"title":"firestoreAdd","icon":"code","href":"/cloud/actions/firestoreAdd"},{"title":"firestoreDelete","icon":"code","href":"/cloud/actions/firestoreDelete"},{"title":"firestoreGet","icon":"code","href":"/cloud/actions/firestoreGet"},{"title":"firestoreSet","icon":"code","href":"/cloud/actions/firestoreSet"},{"title":"firestoreUpdate","icon":"code","href":"/cloud/actions/firestoreUpdate"},{"title":"firestoreMerge","icon":"code","href":"/cloud/actions/firestoreMerge"}]},{"group":"Snapshots","pages":[{"title":"Change Types","icon":"code","href":"/cloud/snapshots/getChangeType"},{"title":"readSnapshot","icon":"code","href":"/cloud/snapshots/readSnapshot"},{"title":"readQuerySnapshot","icon":"code","href":"/cloud/snapshots/readQuerySnapshot"}]},{"group":"Timestamps","pages":[{"title":"maxTimestamp","icon":"code","href":"/cloud/timestamps/maxTimestamp"},{"title":"hydrateAllTimestamps","icon":"code","href":"/cloud/timestamps/hydrateAllTimestamps"},{"title":"hydrateTimestamp","icon":"code","href":"/cloud/timestamps/hydrateTimestamp"},{"title":"minTimestamp","description":"The `minTimestamp` utility efficiently finds the earliest timestamp from an array of Firestore timestamps. It's essential for applications where tracking the initial occurrence of an event or the first update is crucial.","icon":"code","href":"/cloud/timestamps/minTimestamp"},{"title":"sortTimestamps","icon":"code","href":"/cloud/timestamps/sortTimestamps"},{"title":"timestampToDate","description":"The `timestampToDate` utility adeptly converts serialized Firestore timestamps into JavaScript Date objects. This function is crucial for applications that require manipulating Firestore timestamp data in standard JavaScript date formats.","icon":"code","href":"/cloud/timestamps/timestampToDate"}]},{"group":"Metrics","pages":[{"title":"Metrics Overview","href":"/cloud/metrics/overview"},{"title":"incrementMetric","href":"/cloud/metrics/increment"},{"title":"updateMetric","href":"/cloud/metrics/update"},{"title":"Types Reference","href":"/cloud/metrics/types"},{"title":"Utilities","href":"/cloud/metrics/utilities"}]}]}]},"basePath":"","title":"sortTimestamps - Firebridge","buildId":"dpl_G9nrg4qeJSZtah1Ziwbc2n6WkLch","deploymentId":"dpl_G9nrg4qeJSZtah1Ziwbc2n6WkLch","dynamics":[],"chunks":[]}