-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into issues/7-authentication
- Loading branch information
Showing
15 changed files
with
565 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
part of '../kiota_abstractions.dart'; | ||
|
||
/// Interface for a date only object. | ||
/// | ||
/// This interface provides an abstraction layer over date only objects. | ||
/// It is used to represent date only values in a serialization format agnostic | ||
/// way. | ||
/// | ||
/// It can only be used to represent a date in the Gregorian calendar. | ||
abstract class DateOnly { | ||
/// Extracts the date part of a [DateTime] and creates an object implementing | ||
/// [DateOnly]. | ||
factory DateOnly.fromDateTime(DateTime dateTime) { | ||
return _DateOnlyImpl( | ||
day: dateTime.day, | ||
month: dateTime.month, | ||
year: dateTime.year, | ||
); | ||
} | ||
|
||
/// This factory uses the [DateTime.parse] method to create an object | ||
/// implementing [DateOnly]. | ||
factory DateOnly.fromDateTimeString(String dateTimeString) { | ||
final date = DateTime.parse(dateTimeString); | ||
|
||
return DateOnly.fromDateTime(date); | ||
} | ||
|
||
/// Creates an object implementing [DateOnly] from the provided components. | ||
factory DateOnly.fromComponents( | ||
int year, [ | ||
int month = 1, | ||
int day = 1, | ||
]) { | ||
return _DateOnlyImpl( | ||
day: day, | ||
month: month, | ||
year: year, | ||
); | ||
} | ||
|
||
/// Gets the year of the date. | ||
int get year; | ||
|
||
/// Gets the month of the date. | ||
int get month; | ||
|
||
/// Gets the day of the date. | ||
int get day; | ||
} | ||
|
||
class _DateOnlyImpl implements DateOnly { | ||
_DateOnlyImpl({ | ||
required this.day, | ||
required this.month, | ||
required this.year, | ||
}); | ||
|
||
@override | ||
final int day; | ||
|
||
@override | ||
final int month; | ||
|
||
@override | ||
final int year; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
part of '../../kiota_abstractions.dart'; | ||
|
||
extension BaseRequestBuilderExtensions<T extends BaseRequestBuilder<T>> | ||
on BaseRequestBuilder<T> { | ||
/// Clones the current request builder using [clone] and sets the given | ||
/// [rawUrl] as the url to use. | ||
/// | ||
/// This utilizes the [RequestInformation.rawUrlKey] to store the raw url | ||
/// in the [pathParameters]. | ||
T withUrl(String rawUrl) => clone() | ||
..pathParameters.addOrReplace(RequestInformation.rawUrlKey, rawUrl); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
part of '../../kiota_abstractions.dart'; | ||
|
||
/// Extension methods for [DateOnly]. | ||
extension DateOnlyExtensions on DateOnly { | ||
/// Converts the [DateOnly] to a [DateTime]. | ||
DateTime toDateTime() => DateTime(year, month, day); | ||
|
||
/// Combines the [DateOnly] with the given [TimeOnly]. | ||
DateTime combine(TimeOnly time) { | ||
return DateTime( | ||
year, | ||
month, | ||
day, | ||
time.hours, | ||
time.minutes, | ||
time.seconds, | ||
time.milliseconds, | ||
); | ||
} | ||
|
||
/// Converts the [DateOnly] to a string in the format `yyyy-MM-dd`. | ||
String toRfc3339String() { | ||
return '${year.toString().padLeft(4, '0')}-${month.toString().padLeft(2, '0')}-${day.toString().padLeft(2, '0')}'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
part of '../../kiota_abstractions.dart'; | ||
|
||
/// Extension methods for [TimeOnly]. | ||
extension TimeOnlyExtensions on TimeOnly { | ||
/// Converts the [TimeOnly] to a [DateTime]. | ||
DateTime toDateTime( | ||
int year, [ | ||
int month = 1, | ||
int day = 1, | ||
]) => | ||
DateTime( | ||
year, | ||
month, | ||
day, | ||
hours, | ||
minutes, | ||
seconds, | ||
milliseconds, | ||
); | ||
|
||
/// Combines the [TimeOnly] with the given [DateOnly]. | ||
DateTime combine(DateOnly date) { | ||
return DateTime( | ||
date.year, | ||
date.month, | ||
date.day, | ||
hours, | ||
minutes, | ||
seconds, | ||
milliseconds, | ||
); | ||
} | ||
|
||
/// Converts the [TimeOnly] to a string in the format `HH:mm:ss` or | ||
/// `HH:mm:ss.SSS` if milliseconds are present. | ||
String toRfc3339String() { | ||
final String fractionString; | ||
if (milliseconds > 0) { | ||
fractionString = '.${milliseconds.toString().padLeft(3, '0')}'; | ||
} else { | ||
fractionString = ''; | ||
} | ||
|
||
return '${hours.toString().padLeft(2, '0')}:${minutes.toString().padLeft(2, '0')}:${seconds.toString().padLeft(2, '0')}$fractionString'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
part of '../kiota_abstractions.dart'; | ||
|
||
/// Interface for a time only object that represents a time of day. | ||
/// | ||
/// This interface provides an abstraction layer over time only objects. | ||
/// It is used to represent time only values in a serialization format agnostic | ||
/// way. | ||
abstract class TimeOnly { | ||
/// Extracts the time part of a [DateTime] and creates an object implementing | ||
/// [TimeOnly]. | ||
factory TimeOnly.fromDateTime(DateTime dateTime) { | ||
return _TimeOnlyImpl( | ||
hours: dateTime.hour, | ||
minutes: dateTime.minute, | ||
seconds: dateTime.second, | ||
milliseconds: dateTime.millisecond, | ||
); | ||
} | ||
|
||
/// This factory uses the [DateTime.parse] method to create an object | ||
/// implementing [TimeOnly]. | ||
factory TimeOnly.fromDateTimeString(String dateTimeString) { | ||
final dateTime = DateTime.parse('2024-01-01 $dateTimeString'); | ||
|
||
return TimeOnly.fromDateTime(dateTime); | ||
} | ||
|
||
/// Constructs an object implementing [TimeOnly] from the provided components. | ||
factory TimeOnly.fromComponents( | ||
int hours, | ||
int minutes, [ | ||
int seconds = 0, | ||
int milliseconds = 0, | ||
]) { | ||
return _TimeOnlyImpl( | ||
hours: hours, | ||
minutes: minutes, | ||
seconds: seconds, | ||
milliseconds: milliseconds, | ||
); | ||
} | ||
|
||
/// Gets the hours of the time. | ||
int get hours; | ||
|
||
/// Gets the minutes of the time. | ||
int get minutes; | ||
|
||
/// Gets the seconds of the time. | ||
int get seconds; | ||
|
||
/// Gets the milliseconds of the time. | ||
int get milliseconds; | ||
} | ||
|
||
class _TimeOnlyImpl implements TimeOnly { | ||
_TimeOnlyImpl({ | ||
required this.hours, | ||
required this.minutes, | ||
required this.seconds, | ||
required this.milliseconds, | ||
}); | ||
|
||
@override | ||
final int hours; | ||
|
||
@override | ||
final int minutes; | ||
|
||
@override | ||
final int seconds; | ||
|
||
@override | ||
final int milliseconds; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ environment: | |
|
||
dependencies: | ||
std_uritemplate: ^0.0.52 | ||
uuid: ^4.3.3 | ||
|
||
dev_dependencies: | ||
strict: ^2.0.0 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// ignore_for_file: avoid_redundant_argument_values | ||
|
||
import 'package:kiota_abstractions/kiota_abstractions.dart'; | ||
import 'package:test/test.dart'; | ||
|
||
void main() { | ||
group('DateOnly', () { | ||
test('fromDateTimeString and toRfc3339String', () { | ||
expect( | ||
DateOnly.fromDateTimeString('2021-01-01').toRfc3339String(), | ||
'2021-01-01', | ||
); | ||
}); | ||
|
||
test('round trip', () { | ||
final fromString = DateOnly.fromDateTimeString('2021-01-01'); | ||
final toString = fromString.toRfc3339String(); | ||
expect(toString, '2021-01-01'); | ||
|
||
final roundTrip = DateOnly.fromDateTimeString(toString); | ||
final roundTripString = roundTrip.toRfc3339String(); | ||
expect(roundTripString, '2021-01-01'); | ||
}); | ||
|
||
test('fromDateTime', () { | ||
final dateTime = DateTime(2024, 2, 3, 12, 34, 56); | ||
expect( | ||
DateOnly.fromDateTime(dateTime).toRfc3339String(), | ||
'2024-02-03', | ||
); | ||
}); | ||
|
||
test('fromComponents', () { | ||
expect( | ||
DateOnly.fromComponents(2021, 1, 1).toRfc3339String(), | ||
'2021-01-01', | ||
); | ||
}); | ||
}); | ||
} |
Oops, something went wrong.