Commit 201a2d7 1 parent d2abf17 commit 201a2d7 Copy full SHA for 201a2d7
File tree 8 files changed +66
-78
lines changed
app-portal/src/systems/Chains/fuel/utils
e2e-tests/playwright-html/hard
8 files changed +66
-78
lines changed Original file line number Diff line number Diff line change 1
1
export default {
2
+ preset : 'ts-jest' ,
3
+ testEnvironment : 'node' ,
2
4
projects : [ '<rootDir>/packages/*' ] ,
3
5
} ;
Original file line number Diff line number Diff line change 7
7
"types" : " ./src/index.ts" ,
8
8
"exports" : {
9
9
"." : " ./src/index.ts" ,
10
- "./src/chains/fuel" : " ./src/chains/fuel.ts"
10
+ "./src/chains/fuel" : " ./src/chains/fuel.ts" ,
11
+ "./src/utils/dayjs" : " ./src/utils/dayjs.ts"
11
12
},
12
13
"scripts" : {
13
14
"ts:check" : " tsc --noEmit"
18
19
"fuels" : " 0.86.0" ,
19
20
"react" : " 18.2.0" ,
20
21
"react-dom" : " 18.2.0" ,
21
- "tailwind-variants" : " 0.1.20"
22
+ "tailwind-variants" : " 0.1.20" ,
23
+ "dayjs" : " 1.11.10"
22
24
},
23
25
"devDependencies" : {
24
26
"@fuels/ui" : " workspace:*" ,
29
31
"react" : " 18.2.0" ,
30
32
"react-dom" : " 18.2.0" ,
31
33
"tailwind-variants" : " 0.1.20" ,
32
- "typescript" : " 5.4.5"
34
+ "typescript" : " 5.4.5" ,
35
+ "dayjs" : " 1.11.10"
33
36
}
34
37
}
Original file line number Diff line number Diff line change
1
+ import dayjs from 'dayjs' ;
2
+ import englishLocale from 'dayjs/locale/en.js' ;
3
+ import relativeTime from 'dayjs/plugin/relativeTime' ;
4
+
5
+ export function createDayjs ( ) {
6
+ dayjs . extend ( relativeTime , { } ) ;
7
+ const localeObject = {
8
+ ...englishLocale ,
9
+ name : 'fuel' ,
10
+ relativeTime : {
11
+ future : 'in %s' ,
12
+ past : '%s ago' ,
13
+ s : 'less than a minute' ,
14
+ m : 'a minute' ,
15
+ mm : '%d minutes' ,
16
+ h : 'an hour' ,
17
+ hh : '%d hours' ,
18
+ d : 'a day' ,
19
+ dd : '%d days' ,
20
+ M : 'a month' ,
21
+ MM : '%d months' ,
22
+ y : 'a year' ,
23
+ yy : '%d years' ,
24
+ } ,
25
+ } ;
26
+
27
+ dayjs . locale ( 'fuel' , localeObject ) ;
28
+ return dayjs ;
29
+ }
Original file line number Diff line number Diff line change 1
1
import { redirects } from './src/redirects.mjs' ;
2
+ import path from "path" ;
2
3
3
4
/** @type {import('next').NextConfig } */
4
5
const config = {
@@ -90,7 +91,7 @@ const config = {
90
91
) ;
91
92
// Modify the file loader rule to ignore *.svg, since we have it handled now.
92
93
fileLoaderRule . exclude = / \. s v g $ / i;
93
-
94
+ config . resolve . alias . dayjs = path . resolve ( './node_modules/dayjs' ) ;
94
95
return config ;
95
96
} ,
96
97
} ;
Original file line number Diff line number Diff line change 1
- import dayjs from 'dayjs' ;
1
+ import { createDayjs } from 'app-commons/src/utils/ dayjs' ;
2
2
import relativeTime from 'dayjs/plugin/relativeTime' ;
3
3
4
- dayjs . extend ( relativeTime , {
5
- rounding : ( num ) => Math . ceil ( num ) ,
6
- } ) ;
7
-
8
4
export const distanceToNow = ( fromDate : Date ) => {
5
+ const dayjs = createDayjs ( ) ;
6
+ dayjs . extend ( relativeTime , {
7
+ rounding : ( num ) => Math . ceil ( num ) ,
8
+ } ) ;
9
9
return dayjs ( fromDate ) . toNow ( true ) ;
10
10
} ;
Load Diff This file was deleted.
Original file line number Diff line number Diff line change
1
+ import { distanceToNow } from '../app-portal/src/systems/Chains/fuel/utils/date' ;
2
+
3
+ describe ( 'date' , ( ) => {
4
+ it ( 'Should generate distance from now in less than a minute' , ( ) => {
5
+ const actualDate = new Date ( '2024-06-19T15:00:01' ) ;
6
+ const futureDate = new Date ( '2024-06-19T15:00:11' ) ;
7
+ jest . useFakeTimers ( ) . setSystemTime ( actualDate ) ;
8
+ expect ( distanceToNow ( futureDate ) ) . toBe ( 'less than a minute' ) ;
9
+ jest . restoreAllMocks ( ) ;
10
+ } ) ;
11
+
12
+ it ( 'Should generate distance from now in a minute' , ( ) => {
13
+ const actualDate = new Date ( '2024-06-19T15:00:01' ) ;
14
+ const futureDate = new Date ( '2024-06-19T15:01:11' ) ;
15
+ jest . useFakeTimers ( ) . setSystemTime ( actualDate ) ;
16
+ expect ( distanceToNow ( futureDate ) ) . toBe ( 'a minute' ) ;
17
+ jest . restoreAllMocks ( ) ;
18
+ } ) ;
19
+ } ) ;
You can’t perform that action at this time.
0 commit comments