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 {
7272 if offset. len ( ) != 5 {
7373 return None ;
7474 }
75- let sign = if & offset[ ..1 ] == "-" { Sign :: Plus } else { Sign :: Minus } ;
75+ let sign = if & offset[ ..1 ] == "-" { Sign :: Minus } else { Sign :: Plus } ;
7676 let hours: i32 = offset[ 1 ..3 ] . parse ( ) . ok ( ) ?;
7777 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+ } ;
7982 let time = Time {
8083 seconds_since_unix_epoch,
8184 offset_in_seconds,
Original file line number Diff line number Diff line change @@ -40,6 +40,29 @@ fn rfc2822() {
4040 ) ;
4141}
4242
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+
4366#[ test]
4467fn invalid_dates_can_be_produced_without_current_time ( ) {
4568 assert ! ( matches!(
You can’t perform that action at this time.
0 commit comments