Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
2e183b62
Unverified
Commit
2e183b62
authored
Aug 01, 2019
by
Zachary Anderson
Committed by
GitHub
Aug 01, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[flutter_tool] Include the local timezone in analytics timestamp (#37345)
parent
0d6a962b
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
37 additions
and
4 deletions
+37
-4
time.dart
packages/flutter_tools/lib/src/base/time.dart
+15
-0
usage.dart
packages/flutter_tools/lib/src/reporting/usage.dart
+2
-2
analytics_test.dart
...ages/flutter_tools/test/general.shard/analytics_test.dart
+2
-2
time_test.dart
packages/flutter_tools/test/general.shard/time_test.dart
+18
-0
No files found.
packages/flutter_tools/lib/src/base/time.dart
View file @
2e183b62
...
...
@@ -32,3 +32,18 @@ class _FixedTimeClock extends SystemClock {
@override
DateTime
now
()
=>
_fixedTime
;
}
/// Format time as 'yyyy-MM-dd HH:mm:ss Z' where Z is the difference between the
/// timezone of t and UTC formatted according to RFC 822.
String
formatDateTime
(
DateTime
t
)
{
final
String
sign
=
t
.
timeZoneOffset
.
isNegative
?
'-'
:
'+'
;
final
Duration
tzOffset
=
t
.
timeZoneOffset
.
abs
();
final
int
hoursOffset
=
tzOffset
.
inHours
;
final
int
minutesOffset
=
tzOffset
.
inMinutes
-
(
Duration
.
minutesPerHour
*
hoursOffset
);
assert
(
hoursOffset
<
24
);
assert
(
minutesOffset
<
60
);
String
twoDigits
(
int
n
)
=>
(
n
>=
10
)
?
'
$n
'
:
'0
$n
'
;
return
'
$t
$sign${twoDigits(hoursOffset)}${twoDigits(minutesOffset)}
'
;
}
packages/flutter_tools/lib/src/reporting/usage.dart
View file @
2e183b62
...
...
@@ -223,7 +223,7 @@ class _UsageImpl implements Usage {
final
Map
<
String
,
String
>
paramsWithLocalTime
=
<
String
,
String
>{
...?
parameters
,
cdKey
(
CustomDimensions
.
localTime
):
systemClock
.
now
().
toString
(
),
cdKey
(
CustomDimensions
.
localTime
):
formatDateTime
(
systemClock
.
now
()
),
};
_analytics
.
sendScreenView
(
command
,
parameters:
paramsWithLocalTime
);
}
...
...
@@ -240,7 +240,7 @@ class _UsageImpl implements Usage {
final
Map
<
String
,
String
>
paramsWithLocalTime
=
<
String
,
String
>{
...?
parameters
,
cdKey
(
CustomDimensions
.
localTime
):
systemClock
.
now
().
toString
(
),
cdKey
(
CustomDimensions
.
localTime
):
formatDateTime
(
systemClock
.
now
()
),
};
_analytics
.
sendEvent
(
category
,
parameter
,
parameters:
paramsWithLocalTime
);
...
...
packages/flutter_tools/test/general.shard/analytics_test.dart
View file @
2e183b62
...
...
@@ -212,7 +212,7 @@ void main() {
final
String
log
=
fs
.
file
(
'analytics.log'
).
readAsStringSync
();
final
DateTime
dateTime
=
DateTime
.
fromMillisecondsSinceEpoch
(
kMillis
);
expect
(
log
.
contains
(
dateTime
.
toString
(
)),
isTrue
);
expect
(
log
.
contains
(
formatDateTime
(
dateTime
)),
isTrue
);
},
overrides:
<
Type
,
Generator
>{
FileSystem:
()
=>
memoryFileSystem
,
SystemClock:
()
=>
mockClock
,
...
...
@@ -237,7 +237,7 @@ void main() {
final
String
log
=
fs
.
file
(
'analytics.log'
).
readAsStringSync
();
final
DateTime
dateTime
=
DateTime
.
fromMillisecondsSinceEpoch
(
kMillis
);
expect
(
log
.
contains
(
dateTime
.
toString
(
)),
isTrue
);
expect
(
log
.
contains
(
formatDateTime
(
dateTime
)),
isTrue
);
},
overrides:
<
Type
,
Generator
>{
FileSystem:
()
=>
memoryFileSystem
,
SystemClock:
()
=>
mockClock
,
...
...
packages/flutter_tools/test/general.shard/time_test.dart
View file @
2e183b62
...
...
@@ -18,4 +18,22 @@ void main() {
expect
(
clock
.
ago
(
const
Duration
(
days:
10
)),
DateTime
(
1991
,
8
,
13
));
});
});
group
(
'formatting'
,
()
{
test
(
'can round-trip formatted time'
,
()
{
final
DateTime
time
=
DateTime
(
1991
,
7
,
31
);
expect
(
time
.
isUtc
,
isFalse
);
// formatDateTime() adds a timezone offset to DateTime.toString().
final
String
formattedTime
=
formatDateTime
(
time
);
// If a date time string has a timezone offset, DateTime.tryParse()
// converts the parsed time to UTC.
final
DateTime
parsedTime
=
DateTime
.
tryParse
(
formattedTime
);
expect
(
parsedTime
,
isNotNull
);
expect
(
parsedTime
.
isUtc
,
isTrue
);
// Convert the parsed time (which should be utc) to the local timezone and
// compare against the original time which is in the local timezone. They
// should be the same.
expect
(
parsedTime
.
toLocal
(),
equals
(
time
));
});
});
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment