BreakCalculatorExtension.cs (1231B)
1 // BSD 3-Clause License 2 // Copyright(c) 2018-2020 René Wagner 3 // https://git.sr.ht/~rwa/worktimehero 4 5 using System; 6 7 namespace WorkTimeHero 8 { 9 public static class BreakCalculatorExtension 10 { 11 public static TimeSpan CalculateBreak( this TimeSpan currentWorkTime ) 12 { 13 if ( currentWorkTime > new TimeSpan( 6, 45, 0 ) ) 14 { 15 return new TimeSpan( 0, 45, 0 ); 16 } 17 18 if ( currentWorkTime > new TimeSpan( 6, 0, 0 ) ) 19 { 20 return currentWorkTime - new TimeSpan( 6, 0, 0 ); 21 } 22 23 if ( currentWorkTime > new TimeSpan( 4, 30, 0 ) ) 24 { 25 return new TimeSpan( 0, 30, 0 ); 26 } 27 28 if ( currentWorkTime > new TimeSpan( 4, 15, 0 ) ) 29 { 30 return currentWorkTime - new TimeSpan( 4, 0, 0 ); 31 } 32 33 if ( currentWorkTime > new TimeSpan( 2, 15, 0 ) ) 34 { 35 return new TimeSpan( 0, 15, 0 ); 36 } 37 38 if ( currentWorkTime > new TimeSpan( 2, 0, 0 ) ) 39 { 40 return currentWorkTime - new TimeSpan( 2, 0, 0 ); 41 } 42 43 return new TimeSpan(); 44 } 45 } 46 }