mirror of
https://github.com/flutter/flutter.git
synced 2025-06-03 00:51:18 +00:00

* Update project.pbxproj files to say Flutter rather than Chromium Also, the templates now have an empty organization so that we don't cause people to give their apps a Flutter copyright. * Update the copyright notice checker to require a standard notice on all files * Update copyrights on Dart files. (This was a mechanical commit.) * Fix weird license headers on Dart files that deviate from our conventions; relicense Shrine. Some were already marked "The Flutter Authors", not clear why. Their dates have been normalized. Some were missing the blank line after the license. Some were randomly different in trivial ways for no apparent reason (e.g. missing the trailing period). * Clean up the copyrights in non-Dart files. (Manual edits.) Also, make sure templates don't have copyrights. * Fix some more ORGANIZATIONNAMEs
50 lines
1.5 KiB
Dart
50 lines
1.5 KiB
Dart
// Copyright 2014 The Flutter Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
import 'context.dart';
|
|
|
|
/// The current system clock instance.
|
|
SystemClock get systemClock => context.get<SystemClock>();
|
|
|
|
/// A class for making time based operations testable.
|
|
class SystemClock {
|
|
/// A const constructor to allow subclasses to be const.
|
|
const SystemClock();
|
|
|
|
/// Create a clock with a fixed current time.
|
|
const factory SystemClock.fixed(DateTime time) = _FixedTimeClock;
|
|
|
|
/// Retrieve the current time.
|
|
DateTime now() => DateTime.now();
|
|
|
|
/// Compute the time a given duration ago.
|
|
DateTime ago(Duration duration) {
|
|
return now().subtract(duration);
|
|
}
|
|
}
|
|
|
|
class _FixedTimeClock extends SystemClock {
|
|
const _FixedTimeClock(this._fixedTime);
|
|
|
|
final DateTime _fixedTime;
|
|
|
|
@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)}';
|
|
}
|