Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions lib/src/calendars/islamic_yearmonthday_calculator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,7 @@ class IslamicYearMonthDayCalculator extends RegularYearMonthDayCalculator {
case IslamicLeapYearPattern.indian:
return 690562340; // 0b101001001010010010010100100100
case IslamicLeapYearPattern.habashAlHasib:
return 153692453; // 0b001001001010010010100100100101
default:
throw ArgumentError.value(leapYearPattern.index, 'leapYearPattern');
return 153692453;
}
}

Expand All @@ -182,8 +180,6 @@ class IslamicYearMonthDayCalculator extends RegularYearMonthDayCalculator {
return _daysAtAstronomicalEpoch;
case IslamicEpoch.civil:
return _daysAtCivilEpoch;
default:
throw ArgumentError.value(epoch.index, 'epoch');
}
}
}
2 changes: 0 additions & 2 deletions lib/src/calendars/week_year_rules.dart
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,6 @@ abstract class WeekYearRules {
case CalendarWeekRule.firstFullWeek:
minDaysInFirstWeek = 7;
break;
default:
throw ArgumentError('Unsupported CalendarWeekRule: $calendarWeekRule');
}
return SimpleWeekYearRule(minDaysInFirstWeek, firstDayOfWeek, true);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/src/platforms/vm.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import 'dart:async';
import 'dart:collection';
import 'dart:io' as io;
import 'package:universal_io/io.dart' as io;

import 'package:time_machine2/src/time_machine_internal.dart';
import 'package:time_machine2/src/timezones/datetimezone_providers.dart';
Expand Down
37 changes: 26 additions & 11 deletions lib/src/platforms/web.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// Use of this source code is governed by the Apache License 2.0, as found in the LICENSE.txt file.

import 'dart:async';
import 'dart:js';
import 'dart:js_interop';

import 'package:time_machine2/src/time_machine_internal.dart';
import 'package:time_machine2/src/timezones/datetimezone_providers.dart';
Expand Down Expand Up @@ -53,19 +53,34 @@ class TimeMachine {
// {locale: en-US, numberingSystem: latn, calendar: gregory, timeZone: America/New_York, year: numeric, month: numeric, day: numeric}
static void _readIntlObject() {
try {
JsObject options = context['Intl']
.callMethod('DateTimeFormat')
.callMethod('resolvedOptions');
final dateTimeFormat = _DateTimeFormat();
final options = dateTimeFormat.resolvedOptions();

_locale = options['locale'];
_timeZoneId = options['timeZone'];
_numberingSystem = options['numberingSystem'];
_calendar = options['calendar'];
_yearFormat = options['year'];
_monthFormat = options['month'];
_dayFormat = options['day'];
_locale = options.locale.toDart;
_timeZoneId = options.timeZone.toDart;
_numberingSystem = options.numberingSystem.toDart;
_calendar = options.calendar.toDart;
_yearFormat = options.year.toDart;
_monthFormat = options.month.toDart;
_dayFormat = options.day.toDart;
} catch (e, s) {
print('Failed to get platform local information.\n$e\n$s');
}
}
}

@JS('Intl.DateTimeFormat')
extension type _DateTimeFormat._(JSObject _) implements JSObject {
external _DateTimeFormat();
external _ResolvedOptions resolvedOptions();
}

extension type _ResolvedOptions._(JSObject _) implements JSObject {
external JSString get locale;
external JSString get timeZone;
external JSString get numberingSystem;
external JSString get calendar;
external JSString get year;
external JSString get month;
external JSString get day;
}
4 changes: 2 additions & 2 deletions lib/src/text/parse_result.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class ParseResult<T> {
throw StateError(
'Parse operation succeeded, so no exception is available');
}
return _errorProvider!();
return _errorProvider();
}

/// Gets the value from the parse operation if it was successful, or throws an exception indicating the parse failure
Expand All @@ -56,7 +56,7 @@ class ParseResult<T> {
if (_errorProvider == null) {
return _value;
}
throw _errorProvider!();
throw _errorProvider();
}

/// Returns the success value, and sets the out parameter to either
Expand Down
2 changes: 1 addition & 1 deletion lib/src/text/zoneddatetime_pattern_parser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ class _ZonedDateTimeParseBucket extends ParseBucket<ZonedDateTime> {
}
}
value.move(value.index + longestSoFar.length);
return _zoneProvider!
return _zoneProvider
.getDateTimeZoneSync(longestSoFar); // [longestSoFar];
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/src/timezones/idatetimezone_writer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/// Use of this source code is governed by the Apache License 2.0,
/// as found in the LICENSE.txt file.

import 'dart:io';
import 'package:universal_io/io.dart';

import 'package:time_machine2/time_machine2.dart';

Expand Down
2 changes: 0 additions & 2 deletions lib/src/timezones/tzdb_stream_reader.dart
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,6 @@ class TzdbStreamReader {
return FixedDateTimeZone.read(reader, id);
case DateTimeZoneType.precalculated:
return PrecalculatedDateTimeZone.read(reader, id);
default:
throw Exception('Unknown zone type: $type');
}
}
}
1 change: 1 addition & 0 deletions lib/time_machine2.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import 'src/platforms/platform_io.dart'
// `dart.library.js` is compatible with node and browser via dart2js -- `dart.library.html` will only work for the browser
// or at lest it seemed it should be, when I tried `dart.library.js` in chrome, it failed to evaluate to true
if (dart.library.html) 'src/platforms/web.dart'
if (dart.library.js_interop) 'src/platforms/web.dart'
if (dart.library.io) 'src/platforms/vm.dart' as time_machine;

export 'src/calendar_system.dart' show CalendarSystem;
Expand Down
3 changes: 2 additions & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ platforms:
# SDK's lower bound must be compatible with the current version pushed with Flutter
# ./flutter --version
environment:
sdk: ">=2.19.0 <4.0.0"
sdk: ">=3.3.0 <4.0.0"

# Verify flutter_test dependency compatibility first before updating any constraints
# https://github.com/flutter/flutter/blob/master/packages/flutter_test/pubspec.yaml
Expand All @@ -23,6 +23,7 @@ dependencies:
collection: ^1.18.0
http: ^1.2.2
meta: ^1.15.0
universal_io: ^2.2.0

dev_dependencies:
args: ^2.0.0
Expand Down
2 changes: 1 addition & 1 deletion test/testing/test_fx.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// Use of this source code is governed by the Apache License 2.0, as found in the LICENSE.txt file.
import 'dart:async';
import 'dart:mirrors';
import 'dart:io';
import 'package:universal_io/io.dart';

import 'package:test/test.dart';
import 'package:time_machine2/src/time_machine_internal.dart';
Expand Down
2 changes: 1 addition & 1 deletion tool/culture_compiler/decode_to_json.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import 'dart:convert';
import 'dart:io';
import 'package:universal_io/io.dart';
import 'dart:typed_data';

import 'package:time_machine2/src/time_machine_internal.dart';
Expand Down
2 changes: 1 addition & 1 deletion tool/culture_compiler/encode_dart.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import 'dart:io';
import 'package:universal_io/io.dart';
import 'dart:typed_data';

import 'package:path/path.dart' as p;
Expand Down
2 changes: 1 addition & 1 deletion tool/culture_compiler/encode_json_to_bin.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import 'dart:convert';
import 'dart:io';
import 'package:universal_io/io.dart';

import 'package:time_machine2/src/time_machine_internal.dart';

Expand Down
2 changes: 1 addition & 1 deletion tool/tzdb_compiler/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Portions of this work are Copyright 2018 The Noda Time Authors. All rights reserved.
// Use of this source code is governed by the Apache License 2.0, as found in the LICENSE.txt file.

import 'dart:io';
import 'package:universal_io/io.dart';
import 'dart:typed_data';

import 'package:path/path.dart' as path;
Expand Down
2 changes: 1 addition & 1 deletion tool/tzdb_compiler/tzdb/cldr_windows_zone_parser.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import 'dart:io' as io;
import 'package:universal_io/io.dart' as io;

import 'package:xml/xml.dart' as xml;

Expand Down
2 changes: 1 addition & 1 deletion tool/tzdb_compiler/tzdb/file_source.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import 'dart:io';
import 'package:universal_io/io.dart';
import 'dart:convert';

import 'package:archive/archive.dart';
Expand Down
2 changes: 1 addition & 1 deletion tool/tzdb_compiler/tzdb/tzdb_zone_info_compiler.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Portions of this work are Copyright 2018 The Noda Time Authors. All rights reserved.
// Use of this source code is governed by the Apache License 2.0, as found in the LICENSE.txt file.

import 'dart:io';
import 'package:universal_io/io.dart';

import 'package:http/http.dart' as http;
import 'package:time_machine2/src/time_machine_internal.dart';
Expand Down