@@ -6496,6 +6496,85 @@ describe('OpenAPI formula (e2e)', () => {
64966496 expect ( record2 . data . fields [ field2 . name ] ) . toEqual ( 27 ) ;
64976497 } ) ;
64986498
6499+ it ( 'should default formula timeZone when missing' , async ( ) => {
6500+ const inputIso = '2024-02-28T00:00:00+09:00' ;
6501+ const defaultTimeZone = Intl . DateTimeFormat ( ) . resolvedOptions ( ) . timeZone ;
6502+
6503+ const field = await createField ( table . id , {
6504+ type : FieldType . Formula ,
6505+ options : {
6506+ expression : `DAY("${ inputIso } ")` ,
6507+ } ,
6508+ } ) ;
6509+
6510+ const fieldOptions = field . options as { timeZone ?: string } | undefined ;
6511+ expect ( fieldOptions ?. timeZone ) . toEqual ( defaultTimeZone ) ;
6512+
6513+ const record = await getRecord ( table . id , table . records [ 0 ] . id ) ;
6514+ const expectedDay = Number (
6515+ new Intl . DateTimeFormat ( 'en-GB' , {
6516+ timeZone : defaultTimeZone ,
6517+ day : '2-digit' ,
6518+ } ) . format ( new Date ( inputIso ) )
6519+ ) ;
6520+
6521+ expect ( record . data . fields [ field . name ] ) . toEqual ( expectedDay ) ;
6522+ } ) ;
6523+
6524+ it ( 'should bucket Created On records using NOW() formula' , async ( ) => {
6525+ const createdOnField = await createField ( table . id , {
6526+ name : 'Created On' ,
6527+ type : FieldType . Date ,
6528+ options : {
6529+ formatting : {
6530+ date : DateFormattingPreset . ISO ,
6531+ time : TimeFormatting . Hour24 ,
6532+ timeZone : 'UTC' ,
6533+ } ,
6534+ } ,
6535+ } ) ;
6536+
6537+ const formulaField = await createField ( table . id , {
6538+ name : 'Pitch Day' ,
6539+ type : FieldType . Formula ,
6540+ options : {
6541+ expression : `IF(DATETIME_DIFF(NOW(), {${ createdOnField . id } }, "day")<1, "Today", IF(DATETIME_DIFF(NOW(), {${ createdOnField . id } }, "day")<2, "Yesterday", "Older"))` ,
6542+ timeZone : 'UTC' ,
6543+ } ,
6544+ } ) ;
6545+
6546+ const now = Date . now ( ) ;
6547+ const records = await createRecords ( table . id , {
6548+ fieldKeyType : FieldKeyType . Id ,
6549+ records : [
6550+ {
6551+ fields : {
6552+ [ createdOnField . id ] : new Date ( now - 2 * 60 * 60 * 1000 ) . toISOString ( ) ,
6553+ } ,
6554+ } ,
6555+ {
6556+ fields : {
6557+ [ createdOnField . id ] : new Date ( now - 26 * 60 * 60 * 1000 ) . toISOString ( ) ,
6558+ } ,
6559+ } ,
6560+ {
6561+ fields : {
6562+ [ createdOnField . id ] : new Date ( now - 3 * 24 * 60 * 60 * 1000 ) . toISOString ( ) ,
6563+ } ,
6564+ } ,
6565+ ] ,
6566+ } ) ;
6567+
6568+ const todayRecord = await getRecord ( table . id , records . records [ 0 ] . id ) ;
6569+ expect ( todayRecord . data . fields [ formulaField . name ] ) . toEqual ( 'Today' ) ;
6570+
6571+ const yesterdayRecord = await getRecord ( table . id , records . records [ 1 ] . id ) ;
6572+ expect ( yesterdayRecord . data . fields [ formulaField . name ] ) . toEqual ( 'Yesterday' ) ;
6573+
6574+ const olderRecord = await getRecord ( table . id , records . records [ 2 ] . id ) ;
6575+ expect ( olderRecord . data . fields [ formulaField . name ] ) . toEqual ( 'Older' ) ;
6576+ } ) ;
6577+
64996578 it ( 'should evaluate timezone-aware formatting formulas referencing fields' , async ( ) => {
65006579 const dateField = await createField ( table . id , {
65016580 name : 'tz source' ,
0 commit comments