Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix DateTime conversion #33

Merged
merged 5 commits into from
Oct 16, 2022
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
5 changes: 3 additions & 2 deletions lib/src/util.dart
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,10 @@ class JsonObject {
case Uri:
return Uri.parse(v) as T;
case DateTime:
return DateTime.fromMillisecondsSinceEpoch(v * 1000) as T;
return DateTime.fromMillisecondsSinceEpoch(((v as num).round() * 1000))
as T;
case Duration:
return Duration(seconds: v) as T;
return Duration(seconds: (v as num).round()) as T;
case String:
case num:
case bool:
Expand Down
9 changes: 7 additions & 2 deletions test/jwt_test.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'package:test/test.dart';
import 'package:jose/src/jwt.dart';
import 'package:jose/src/jwk.dart';
import 'package:jose/src/jwt.dart';
import 'package:test/test.dart';

void main() {
group('JWT Examples from RFC7519', () {
Expand Down Expand Up @@ -153,4 +153,9 @@ void main() {
'AVO9iT5AV4CzvDJCdhSFlQ');
});
});

test('JsonWebTokenClaims can handle doubles in expiration', () {
final claims = JsonWebTokenClaims.fromJson({'exp': 1300819380.0});
expect(claims.expiry, DateTime.fromMillisecondsSinceEpoch(1300819380000));
});
}