SHARE
TWEET

Untitled

a guest May 21st, 2019 70 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package start_finish;
  2.  
  3. import java.time.DayOfWeek;
  4. import java.time.Duration;
  5. import java.time.LocalDateTime;
  6. import java.time.format.DateTimeFormatter;
  7. import java.util.Locale;
  8.  
  9.  
  10.  
  11.  
  12. public class DurataFunctionare
  13. {
  14.     private LocalDateTime start;
  15.     private LocalDateTime end;
  16.    
  17.     private DurataFunctionare(LocalDateTime start, LocalDateTime end){
  18.         this.start=start;
  19.         this.end=end;
  20.     }
  21.     public static DurataFunctionare getInstance(LocalDateTime s, LocalDateTime e){
  22.         if(s==null || e==null){
  23.             return null;
  24.         }
  25.         if(s.isAfter(e)){return null;}
  26.        
  27.     if(s.getDayOfWeek()=DayOfWeek.SATURDAY || e.getDayofWeek()==DayOfWeek.SATURDAY){return null;}
  28.     System.out.println("Am verificat nu este Sambata sau Duminica");
  29.     return new DurataFunctionare(s,e);
  30. }
  31. public static DurataFunctionare getInstance(LocalDateTime s, Duration d){
  32.     if(d==null){return null;}
  33.     return new DurataFunctionare(s , s.plus(d));
  34. }
  35. public static DurataFunctionare getInstance(LocalDateTime s, int zile, int ore, int minute, int secunde){
  36.     Duration
  37.     d=Duration.ofDays(zile).plus(Duration.ofHours(ore).plus(Duration.ofMinutes(minute)).plus(Duration.ofSeconds(secunde)));
  38.     return new DurateFunctionare(s,s.plus(d));
  39. }
  40. public String toString(){
  41.     String s="Activarea incepe" + formatare(start);
  42.     s+= "si se incheie";
  43.     s+=formare(end);
  44.     return s;
  45. }
  46. private String formatare (LocalDateTime locDT){
  47.     Locale RO = new Local ("ro", "RO");
  48.     return locDT.format(DateTimeFormatter.ofPattern("EEEE dd.MM.yyyy 'ora' HH:mm:ss", RO));
  49. }
  50. public static void main (String[] args){
  51.     DurataFunctionare d1=DurataFunctionare.getInstance(LocalDateTime.now(), LocalDateTime.now().plusHours(2));
  52.     System.out.println(d1.toString());
  53. }
  54.    
  55. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top