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

Timezone Control in the GUIDE #820

Merged
merged 61 commits into from
Jun 5, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
9a8bc6e
Allow user to specify a timezone to use in the GUIDE
garrettmflynn Jun 3, 2024
5b826f5
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 3, 2024
4dc776f
Generate timezone list
garrettmflynn Jun 3, 2024
ad1cf97
Merge branch 'main' into timezone
CodyCBakerPhD Jun 3, 2024
303e275
Provide datetime values with a timezone offset specified. Render diff…
garrettmflynn Jun 3, 2024
ad1e9c9
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 3, 2024
31b5fec
More uniform time handling
garrettmflynn Jun 3, 2024
977950f
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 3, 2024
f521e57
Extract timezone offset using timezone awareness. Remove timezone awa…
garrettmflynn Jun 3, 2024
3681429
Merge branch 'timezone' of https://github.com/NeurodataWithoutBorders…
garrettmflynn Jun 3, 2024
4c69fab
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 3, 2024
a195173
Set timezone when converting data
garrettmflynn Jun 3, 2024
7af0222
Add timestamp awareness to forms and conversion process
garrettmflynn Jun 3, 2024
3e74935
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 3, 2024
fae3596
Ensure default values are carried in the preform
garrettmflynn Jun 3, 2024
864c2da
Merge branch 'timezone' of https://github.com/NeurodataWithoutBorders…
garrettmflynn Jun 3, 2024
9b7eb71
Merge branch 'main' into timezone
CodyCBakerPhD Jun 4, 2024
5beaafe
Merge branch 'main' into timezone
CodyCBakerPhD Jun 4, 2024
389c113
Use keywords, categories, and labels to improve the rendering of time…
garrettmflynn Jun 4, 2024
d026cd8
Merge branch 'timezone' of https://github.com/NeurodataWithoutBorders…
garrettmflynn Jun 4, 2024
74856c9
Require timezone and move workflow value resolution into the Dashboar…
garrettmflynn Jun 4, 2024
f868b1e
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 4, 2024
ca3ea2d
Update Dashboard.js
garrettmflynn Jun 4, 2024
720fe30
Merge branch 'timezone' of https://github.com/NeurodataWithoutBorders…
garrettmflynn Jun 4, 2024
d0d49c1
Add non-category timezone information to the end
garrettmflynn Jun 4, 2024
ed416e1
Show long and short name
garrettmflynn Jun 4, 2024
7042094
Instead of always including UTC, add it if the timezone detector has …
garrettmflynn Jun 4, 2024
fa29aa4
Properly resolve promises
garrettmflynn Jun 4, 2024
b619ce3
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 4, 2024
f02a800
Bring dashboard changes directly from the backend configuration PR
garrettmflynn Jun 4, 2024
bf96a46
Update Dashboard.js
garrettmflynn Jun 4, 2024
28bc090
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 4, 2024
90fa005
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 4, 2024
aad5e9a
Merge branch 'main' into timezone
CodyCBakerPhD Jun 4, 2024
b82875d
Rely on Python for timezone information
garrettmflynn Jun 4, 2024
c9370ad
Update GuidedMetadata.js
garrettmflynn Jun 4, 2024
75e2f79
Merge branch 'main' into timezone
garrettmflynn Jun 4, 2024
c8a69fc
Update GuidedSourceData.js
garrettmflynn Jun 4, 2024
6476daf
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 4, 2024
b3fc871
cleanup modules
CodyCBakerPhD Jun 4, 2024
6d03f2e
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 4, 2024
48d8e76
add call to management helpers
CodyCBakerPhD Jun 4, 2024
051bbd5
Merge remote-tracking branch 'origin/timezone' into timezone
CodyCBakerPhD Jun 4, 2024
b440644
remove placeholder
CodyCBakerPhD Jun 4, 2024
5f948c9
object does not mutate
CodyCBakerPhD Jun 4, 2024
eaf29a1
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 4, 2024
8e1b835
adjust fetch calls
CodyCBakerPhD Jun 4, 2024
987e1b2
fix namespace for docs
CodyCBakerPhD Jun 4, 2024
b75e55d
debug import
CodyCBakerPhD Jun 4, 2024
6bd7823
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 4, 2024
d3ba6d1
fix import and parse datetime object
CodyCBakerPhD Jun 4, 2024
d2bec56
Merge remote-tracking branch 'origin/timezone' into timezone
CodyCBakerPhD Jun 4, 2024
3180bc3
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 4, 2024
10aa18b
Sort by category
garrettmflynn Jun 4, 2024
0cc837c
Update timezone.schema.ts
garrettmflynn Jun 4, 2024
37d75d6
Add current timezone if filtered out (e.g. in Actions)
garrettmflynn Jun 5, 2024
1006ac0
Merge branch 'main' into timezone
CodyCBakerPhD Jun 5, 2024
518dd96
Fix workflow loading. Add localstorage data handling back on the web
garrettmflynn Jun 5, 2024
aaaeef7
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 5, 2024
4f3056f
Fix preform page. Add multi-session workflow to show other pages
garrettmflynn Jun 5, 2024
8473378
Merge branch 'timezone' of https://github.com/NeurodataWithoutBorders…
garrettmflynn Jun 5, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { JSONSchemaForm } from "../../../JSONSchemaForm.js";
import { Page } from "../../Page.js";
import { onThrow } from "../../../../errors";

import timezoneSchema from "../../../../../../../schemas/timezone.schema";

// ------------------------------------------------------------------------------
// ------------------------ Preform Configuration -------------------------------
// ------------------------------------------------------------------------------
Expand Down Expand Up @@ -55,6 +57,11 @@ const questions = {
},
},

timezone: {
...timezoneSchema,
title: "What timezone is your data in?",
},

upload_to_dandi: {
type: "boolean",
title: "Would you like to upload your data to DANDI?",
Expand Down
32 changes: 24 additions & 8 deletions src/schemas/base-metadata.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import baseMetadataSchema from './json/base_metadata_schema.json' assert { type:

import { merge } from '../electron/frontend/core/components/pages/utils'
import { drillSchemaProperties } from '../electron/frontend/core/components/pages/guided-mode/data/utils'
import { localTimeZone } from './timezone.schema'

const UV_MATH_FORMAT = `&micro;V`; //`<math xmlns="http://www.w3.org/1998/Math/MathML"><mo>&micro;</mo><mi>V</mi></math>`
const UV_PROPERTIES = ["gain_to_uV", "offset_to_uV"]
Expand Down Expand Up @@ -41,11 +42,17 @@ function getSpeciesInfo(species: any[][] = []) {
}


// Borrowed from https://stackoverflow.com/a/29774197/7290573
function getCurrentDate() {
const date = new Date()
const offset = date.getTimezoneOffset();
return (new Date(date.getTime() - (offset*60*1000))).toISOString();

function getISODateInTimezone(
timezone = localTimeZone
) {
const date = new Date();
const utcDate = new Date(date.toLocaleString('en-US', { timeZone: 'UTC' }));
const tzDate = new Date(date.toLocaleString('en-US', { timeZone: timezone }));
const offset = utcDate.getTime() - tzDate.getTime();

const adjustedDate = new Date(date.getTime() - offset);
return adjustedDate.toISOString();
}


Expand Down Expand Up @@ -101,6 +108,10 @@ export const preprocessMetadataSchema = (schema: any = baseMetadataSchema, globa

copy.order = [ "NWBFile", "Subject" ]

const minDate = "1900-01-01T00:00"
const maxDate = getISODateInTimezone().slice(0, -2)


// Add unit to weight
const subjectProps = copy.properties.Subject.properties
subjectProps.weight.unit = 'kg'
Expand All @@ -121,13 +132,18 @@ export const preprocessMetadataSchema = (schema: any = baseMetadataSchema, globa
strict: false,
description: 'The species of your subject.'
}
subjectProps.date_of_birth.minimum = "1900-01-01T00:00"
subjectProps.date_of_birth.maximum = getCurrentDate().slice(0, -2)

subjectProps.date_of_birth.minimum = minDate
subjectProps.date_of_birth.maximum = maxDate

// copy.order = ['NWBFile', 'Subject']

copy.properties.NWBFile.title = 'General Metadata'
const nwbProps = copy.properties.NWBFile.properties
copy.properties.NWBFile.title = 'General Metadata'

nwbProps.session_start_time.minimum = minDate
nwbProps.session_start_time.maximum = maxDate

nwbProps.keywords.items.description = "Provide a single keyword (e.g. Neural circuits, V1, etc.)"

// Resolve species suggestions
Expand Down
41 changes: 41 additions & 0 deletions src/schemas/timezone.schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@

// const timezones = Intl.supportedValuesOf('timeZone');

const mostCommonTimezonesWithUTCOffset = {
'Pacific/Honolulu': '-10:00',
'America/Anchorage': '-09:00',
'America/Los_Angeles': '-08:00',
'America/Denver': '-07:00',
'America/Chicago': '-06:00',
'America/New_York': '-05:00',
'America/Sao_Paulo': '-03:00',
'Atlantic/Azores': '-01:00',
'Europe/London': '+00:00',
'Europe/Paris': '+01:00',
'Europe/Athens': '+02:00',
'Asia/Jerusalem': '+02:00',
'Europe/Moscow': '+03:00',
'Asia/Dubai': '+04:00',
'Asia/Karachi': '+05:00',
'Asia/Dhaka': '+06:00',
'Asia/Jakarta': '+07:00',
'Asia/Shanghai': '+08:00',
'Asia/Tokyo': '+09:00',
'Australia/Sydney': '+10:00',
'Pacific/Auckland': '+12:00'
};
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is likely to confuse people due to daylight savings time. Most of these timezone names actually have different offsets depending on the day of the year. zoneinfo takes care of this automatically- you input the name of the timezone and it will check the date so that the correct offset is applied. I wish we could apply a simplifying approach like this but honestly I think this is going to confuse a lot of people if implemented this way

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I honestly think a very long dropdown would be better. I know it's not ideal but it is at least accurate

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just pushed the option where we are rendering the browser's acceptable timezones as a native <select> element.

Screenshot 2024-06-03 at 12 21 00 PM

How's this? Would you prefer it to be searchable? What about the formats used by zoneinfo that aren't in America/Chicago format?

Copy link
Collaborator

@CodyCBakerPhD CodyCBakerPhD Jun 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This approach would absolutely need to be searchable (probably as our loose selector); it's overwhelming scrolling through a list that massive

I'd still recommend we simplify with a basic numeric scroller, that's many fewer options and removes the complexity of tying the number to a specific place (which has a somewhat low chance of being exactly the city they are located in)



export const localTimeZone = Intl.DateTimeFormat().resolvedOptions().timeZone;

export default {
type: "string",
description: "Provide a base timezone for all date and time operations in the GUIDE.",
default: localTimeZone,
enum: Object.keys(mostCommonTimezonesWithUTCOffset),
enumLabels: Object.entries(mostCommonTimezonesWithUTCOffset).reduce((acc, [ name, offset ]) => {
acc[name] = `${name} (${offset})`
return acc
}),
strict: true
}
Loading