File tree Expand file tree Collapse file tree 2 files changed +28
-2
lines changed Expand file tree Collapse file tree 2 files changed +28
-2
lines changed Original file line number Diff line number Diff line change @@ -72,10 +72,13 @@ pub(crate) mod function {
72
72
if offset. len ( ) != 5 {
73
73
return None ;
74
74
}
75
- let sign = if & offset[ ..1 ] == "-" { Sign :: Plus } else { Sign :: Minus } ;
75
+ let sign = if & offset[ ..1 ] == "-" { Sign :: Minus } else { Sign :: Plus } ;
76
76
let hours: i32 = offset[ 1 ..3 ] . parse ( ) . ok ( ) ?;
77
77
let minutes: i32 = offset[ 3 ..5 ] . parse ( ) . ok ( ) ?;
78
- let offset_in_seconds = hours * 3600 + minutes * 60 ;
78
+ let mut offset_in_seconds = hours * 3600 + minutes * 60 ;
79
+ if sign == Sign :: Minus {
80
+ offset_in_seconds *= -1 ;
81
+ } ;
79
82
let time = Time {
80
83
seconds_since_unix_epoch,
81
84
offset_in_seconds,
Original file line number Diff line number Diff line change @@ -40,6 +40,29 @@ fn rfc2822() {
40
40
) ;
41
41
}
42
42
43
+ #[ test]
44
+ fn raw ( ) {
45
+ assert_eq ! (
46
+ git_date:: parse( "1660874655 +0800" , None ) . expect( "parsed raw string" ) ,
47
+ Time {
48
+ seconds_since_unix_epoch: 1660874655 ,
49
+ offset_in_seconds: 28800 ,
50
+ sign: Sign :: Plus ,
51
+ } ,
52
+ "could not parse with raw format"
53
+ ) ;
54
+
55
+ assert_eq ! (
56
+ git_date:: parse( "1660874655 -0800" , None ) . expect( "parsed raw string" ) ,
57
+ Time {
58
+ seconds_since_unix_epoch: 1660874655 ,
59
+ offset_in_seconds: -28800 ,
60
+ sign: Sign :: Minus ,
61
+ } ,
62
+ "could not parse with raw format"
63
+ ) ;
64
+ }
65
+
43
66
#[ test]
44
67
fn invalid_dates_can_be_produced_without_current_time ( ) {
45
68
assert ! ( matches!(
You can’t perform that action at this time.
0 commit comments