File tree Expand file tree Collapse file tree 2 files changed +29
-2
lines changed Expand file tree Collapse file tree 2 files changed +29
-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,30 @@ fn rfc2822() {
40
40
) ;
41
41
}
42
42
43
+
44
+ #[ test]
45
+ fn raw ( ) {
46
+ assert_eq ! (
47
+ git_date:: parse( "1660874655 +0800" , None ) . expect( "parsed raw string" ) ,
48
+ Time {
49
+ seconds_since_unix_epoch: 1660874655 ,
50
+ offset_in_seconds: 28800 ,
51
+ sign: Sign :: Plus ,
52
+ } ,
53
+ "could not parse with raw format"
54
+ ) ;
55
+
56
+ assert_eq ! (
57
+ git_date:: parse( "1660874655 -0800" , None ) . expect( "parsed raw string" ) ,
58
+ Time {
59
+ seconds_since_unix_epoch: 1660874655 ,
60
+ offset_in_seconds: -28800 ,
61
+ sign: Sign :: Minus ,
62
+ } ,
63
+ "could not parse with raw format"
64
+ ) ;
65
+ }
66
+
43
67
#[ test]
44
68
fn invalid_dates_can_be_produced_without_current_time ( ) {
45
69
assert ! ( matches!(
You can’t perform that action at this time.
0 commit comments