Skip to content

Commit 4d95622

Browse files
yeion7SaraVieira
authored andcommitted
show right time zone (codesandbox#2590)
* parse utc time * add dependencies to package * use api v2 date-fns * skipLibCheck
1 parent 2aad125 commit 4d95622

File tree

6 files changed

+29
-8
lines changed

6 files changed

+29
-8
lines changed

packages/app/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,8 @@
104104
"console": "^0.7.2",
105105
"console-feed": "CompuIves/console-feed#build2",
106106
"css-modules-loader-core": "^1.1.0",
107+
"date-fns": "^2.4.1",
108+
"date-fns-tz": "^1.0.7",
107109
"debug": "^2.6.8",
108110
"downshift": "^1.0.0-rc.14",
109111
"eslint-plugin-react-hooks": "1.6.0",

packages/app/src/app/pages/Curator/index.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
import React, { useCallback, useEffect, useState } from 'react';
2-
import getTime from 'date-fns/get_time';
3-
import subMonths from 'date-fns/sub_months';
4-
import subWeeks from 'date-fns/sub_weeks';
5-
import format from 'date-fns/format';
2+
import { getTime, subMonths, subWeeks, format } from 'date-fns';
63
import DayPicker from 'react-day-picker';
74
import { Button } from '@codesandbox/common/lib/components/Button';
85
import Margin from '@codesandbox/common/lib/components/spacing/Margin';
@@ -94,7 +91,9 @@ const Curator = inject('store', 'signals')(
9491
Last 6 Months
9592
</Button>
9693
<Button onClick={() => setShowPicker(show => !show)} small>
97-
{selectedDate ? format(selectedDate, 'DD/MM/YYYY') : 'Custom'}
94+
{selectedDate
95+
? format(new Date(selectedDate), 'dd/MM/yyyy')
96+
: 'Custom'}
9897
</Button>
9998
{showPicker ? (
10099
<PickerWrapper>

packages/app/src/app/pages/Dashboard/Content/SandboxGrid/index.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import React from 'react';
22
import { inject, observer } from 'app/componentConnectors';
33

4-
import { distanceInWordsToNow } from 'date-fns';
4+
import { formatDistanceToNow } from 'date-fns';
5+
import { zonedTimeToUtc } from 'date-fns-tz';
56
import { uniq } from 'lodash-es';
67
import { basename } from 'path';
78
import { camelizeKeys } from 'humps';
@@ -45,6 +46,8 @@ const BASE_HEIGHT = 242;
4546
const IS_TABLE = false;
4647

4748
const diff = (a, b) => (a > b ? a - b : b - a);
49+
const distanceInWordsToNow = date =>
50+
formatDistanceToNow(zonedTimeToUtc(date, 'Etc/UTC'));
4851

4952
class SandboxGridComponent extends React.Component<*, State> {
5053
state = {

packages/app/src/app/pages/common/Modals/SelectSandboxModal/Sandbox/index.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React from 'react';
22
import { format } from 'date-fns';
3+
import { zonedTimeToUtc } from 'date-fns-tz';
34
import { getSandboxName } from '@codesandbox/common/lib/utils/get-sandbox-name';
45

56
import { Date, Button } from './elements';
@@ -17,7 +18,12 @@ export default class Sandbox extends React.PureComponent {
1718
{getSandboxName(sandbox)}
1819
{active && ' (Selected)'}
1920
</div>
20-
<Date>{format(sandbox.insertedAt, 'MMM DD, YYYY')}</Date>
21+
<Date>
22+
{format(
23+
zonedTimeToUtc(sandbox.insertedAt, 'Etc/UTC'),
24+
'MMM dd, yyyy'
25+
)}
26+
</Date>
2127
</Button>
2228
);
2329
}

packages/app/tsconfig.check.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"extends": "./tsconfig.json",
33
"exclude": ["codesandbox-browserfs/*"],
44
"compilerOptions": {
5-
"allowJs": false
5+
"allowJs": false,
6+
"skipLibCheck": true
67
}
78
}

yarn.lock

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8982,6 +8982,11 @@ data-urls@^1.0.0, data-urls@^1.0.1:
89828982
whatwg-mimetype "^2.1.0"
89838983
whatwg-url "^7.0.0"
89848984

8985+
date-fns-tz@^1.0.7:
8986+
version "1.0.7"
8987+
resolved "https://registry.yarnpkg.com/date-fns-tz/-/date-fns-tz-1.0.7.tgz#1c80f7592cca5da4fd2085132936dcc7fa9afecd"
8988+
integrity sha512-oNfi/3IxRfmysRIT+QJMbO/44Uj10nApAYJvlayTmNRFZG+JqdOJYXm1DWU65DNlG/ySbuQwpFkGIa3b2XFUVw==
8989+
89858990
[email protected], date-fns@^1.23.0, date-fns@^1.27.2, date-fns@^1.30.1:
89868991
version "1.30.1"
89878992
resolved "https://registry.yarnpkg.com/date-fns/-/date-fns-1.30.1.tgz#2e71bf0b119153dbb4cc4e88d9ea5acfb50dc05c"
@@ -8992,6 +8997,11 @@ date-fns@^2.0.0:
89928997
resolved "https://registry.yarnpkg.com/date-fns/-/date-fns-2.0.0.tgz#52f05c6ae1fe0e395670082c72b690ab781682d0"
89938998
integrity sha512-nGZDA64Ktq5uTWV4LEH3qX+foV4AguT5qxwRlJDzJtf57d4xLNwtwrfb7SzKCoikoae8Bvxf0zdaEG/xWssp/w==
89948999

9000+
date-fns@^2.4.1:
9001+
version "2.4.1"
9002+
resolved "https://registry.yarnpkg.com/date-fns/-/date-fns-2.4.1.tgz#b53f9bb65ae6bd9239437035710e01cf383b625e"
9003+
integrity sha512-2RhmH/sjDSCYW2F3ZQxOUx/I7PvzXpi89aQL2d3OAxSTwLx6NilATeUbe0menFE3Lu5lFkOFci36ivimwYHHxw==
9004+
89959005
date-format@^0.0.0:
89969006
version "0.0.0"
89979007
resolved "https://registry.yarnpkg.com/date-format/-/date-format-0.0.0.tgz#09206863ab070eb459acea5542cbd856b11966b3"

0 commit comments

Comments
 (0)