Skip to main content

DateUtility


import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.Month;
import java.time.format.DateTimeFormatter;

import javax.swing.text.DateFormatter;

public class DateUtility {

 private static final String YYYY_MM_DD_HH_MM_SS_Z = "yyyy-MM-dd HH:mm:ss z";

 public static void main(String[] args) {

  updateJulyDates();
  System.out.println();
  updateFebrurayDates();
  System.out.println();
  System.out.println();

  updateSampleOrderDates();

 }

 public static void updateSampleOrderDates() {

  LocalDateTime DOO = LocalDateTime.of(2018, Month.JULY, 8, 4, 10, 10);// SUNDAY
  LocalDateTime ESD = LocalDateTime.of(2018, Month.JULY, 12, 4, 10, 10);// THURSDAY
  LocalDateTime LDD = LocalDateTime.of(2018, Month.JULY, 16, 4, 10, 10);// MONDAY
  LocalDateTime SBD = LocalDateTime.of(2018, Month.JULY, 10, 4, 10, 10);// TUESDAY
  LocalDateTime RBD = LocalDateTime.of(2018, Month.JULY, 12, 4, 10, 10);// THURSDAY

  System.out.println(" old DOO : " + DOO.format(DateTimeFormatter.ISO_DATE) + " 
   DOW :  " + DOO.getDayOfWeek()
    + "     new DOO :  " + updateDate(DOO).format(DateTimeFormatter.ISO_DATE) + "     DOW :  "
    + updateDate(DOO).getDayOfWeek());
  System.out.println(" old ESD : " + ESD.format(DateTimeFormatter.ISO_DATE) + " 
   DOW :  " + ESD.getDayOfWeek()
    + "   new ESD:  " + updateDate(ESD).format(DateTimeFormatter.ISO_DATE) + "     DOW :  "
    + updateDate(ESD).getDayOfWeek());
  System.out.println(" old LDD: " + LDD.format(DateTimeFormatter.ISO_DATE) + "     DOW :  " + LDD.getDayOfWeek()
    + "     new LDD:  " + updateDate(LDD).format(DateTimeFormatter.ISO_DATE) + "     DOW :  "
    + updateDate(LDD).getDayOfWeek());
  System.out.println(" old SBD: " + SBD.format(DateTimeFormatter.ISO_DATE) + "
     DOW :  " + SBD.getDayOfWeek()
    + "    new SBD:  " + updateDate(SBD).format(DateTimeFormatter.ISO_DATE) + "     DOW :  "
    + updateDate(SBD).getDayOfWeek());
  System.out.println(" old RBD: " + RBD.format(DateTimeFormatter.ISO_DATE) + "     DOW :  " + RBD.getDayOfWeek()
    + "   new RBD:  " + updateDate(RBD).format(DateTimeFormatter.ISO_DATE) + "     DOW :  "
    + updateDate(RBD).getDayOfWeek());

 }

 public static void updateJulyDates() {

  LocalDateTime july_2011 = LocalDateTime.of(2011, Month.JULY, 10, 4, 10, 10);
  LocalDateTime july_2012 = LocalDateTime.of(2012, Month.JULY, 8, 4, 10, 10);
  LocalDateTime july_2013 = LocalDateTime.of(2013, Month.JULY, 7, 4, 10, 10);
  LocalDateTime july_2014 = LocalDateTime.of(2014, Month.JULY, 6, 4, 10, 10);
  LocalDateTime july_2015 = LocalDateTime.of(2015, Month.JULY, 5, 4, 10, 10);
  LocalDateTime july_2016 = LocalDateTime.of(2016, Month.JULY, 10, 4, 10, 10);
  LocalDateTime july_2017 = LocalDateTime.of(2017, Month.JULY, 9, 4, 10, 10);
  LocalDateTime july_2018 = LocalDateTime.of(2018, Month.JULY, 8, 4, 10);

  System.out.println(" old : " + july_2011.format(DateTimeFormatter.ISO_DATE) + "     DOW :  "
    + july_2011.getDayOfWeek() + "    new :  " + updateDate(july_2011).format(DateTimeFormatter.ISO_DATE)
    + "     DOW :  " + updateDate(july_2011).getDayOfWeek());
  System.out.println(" old : " + july_2012.format(DateTimeFormatter.ISO_DATE) + "     DOW :  "
    + july_2012.getDayOfWeek() + "    new :  " + updateDate(july_2012).format(DateTimeFormatter.ISO_DATE)
    + "     DOW :  " + updateDate(july_2012).getDayOfWeek());
  System.out.println(" old : " + july_2013.format(DateTimeFormatter.ISO_DATE) + "     DOW :  "
    + july_2013.getDayOfWeek() + "    new :  " + updateDate(july_2013).format(DateTimeFormatter.ISO_DATE)
    + "     DOW :  " + updateDate(july_2013).getDayOfWeek());
  System.out.println(" old : " + july_2014.format(DateTimeFormatter.ISO_DATE) + "     DOW :  "
    + july_2014.getDayOfWeek() + "    new :  " + updateDate(july_2014).format(DateTimeFormatter.ISO_DATE)
    + "     DOW :  " + updateDate(july_2014).getDayOfWeek());
  System.out.println(" old : " + july_2015.format(DateTimeFormatter.ISO_DATE) + "     DOW :  "
    + july_2015.getDayOfWeek() + "    new :  " + updateDate(july_2015).format(DateTimeFormatter.ISO_DATE)
    + "     DOW :  " + updateDate(july_2015).getDayOfWeek());
  System.out.println(" old : " + july_2016.format(DateTimeFormatter.ISO_DATE) + "     DOW :  "
    + july_2016.getDayOfWeek() + "    new :  " + updateDate(july_2016).format(DateTimeFormatter.ISO_DATE)
    + "     DOW :  " + updateDate(july_2016).getDayOfWeek());
  System.out.println(" old : " + july_2017.format(DateTimeFormatter.ISO_DATE) + "     DOW :  "
    + july_2017.getDayOfWeek() + "    new :  " + updateDate(july_2017).format(DateTimeFormatter.ISO_DATE)
    + "     DOW :  " + updateDate(july_2017).getDayOfWeek());
  System.out.println(" old : " + july_2018.format(DateTimeFormatter.ISO_DATE) + "     DOW :  "
    + july_2018.getDayOfWeek() + "    new :  " + updateDate(july_2018).format(DateTimeFormatter.ISO_DATE)
    + "     DOW :  " + updateDate(july_2018).getDayOfWeek());

 }

 public static void updateFebrurayDates() {

  LocalDateTime feb_2011 = LocalDateTime.of(2011, Month.FEBRUARY, 16, 4, 10, 10);
  LocalDateTime feb_2012 = LocalDateTime.of(2012, Month.FEBRUARY, 15, 4, 10, 10);
  LocalDateTime feb_2013 = LocalDateTime.of(2013, Month.FEBRUARY, 13, 4, 10, 10);
  LocalDateTime feb_2014 = LocalDateTime.of(2014, Month.FEBRUARY, 12, 4, 10, 10);
  LocalDateTime feb_2015 = LocalDateTime.of(2015, Month.FEBRUARY, 11, 4, 10, 10);
  LocalDateTime feb_2016 = LocalDateTime.of(2016, Month.FEBRUARY, 10, 4, 10, 10);
  LocalDateTime feb_2017 = LocalDateTime.of(2017, Month.FEBRUARY, 15, 4, 10, 10);
  LocalDateTime feb_2018 = LocalDateTime.of(2018, Month.FEBRUARY, 14, 4, 10);
  System.out.println();
  System.out.println();

  System.out.println(" old : " + feb_2011.format(DateTimeFormatter.ISO_DATE) + "     DOW :  "
    + feb_2011.getDayOfWeek() + "    new :  " + updateDate(feb_2011).format(DateTimeFormatter.ISO_DATE)
    + "     DOW :  " + updateDate(feb_2011).getDayOfWeek());
  System.out.println(" old : " + feb_2012.format(DateTimeFormatter.ISO_DATE) + "     DOW :  "
    + feb_2012.getDayOfWeek() + "    new :  " + updateDate(feb_2012).format(DateTimeFormatter.ISO_DATE)
    + "     DOW :  " + updateDate(feb_2012).getDayOfWeek());
  System.out.println(" old : " + feb_2013.format(DateTimeFormatter.ISO_DATE) + "     DOW :  "
    + feb_2013.getDayOfWeek() + "    new :  " + updateDate(feb_2013).format(DateTimeFormatter.ISO_DATE)
    + "     DOW :  " + updateDate(feb_2013).getDayOfWeek());
  System.out.println(" old : " + feb_2014.format(DateTimeFormatter.ISO_DATE) + "     DOW :  "
    + feb_2014.getDayOfWeek() + "    new :  " + updateDate(feb_2014).format(DateTimeFormatter.ISO_DATE)
    + "     DOW :  " + updateDate(feb_2014).getDayOfWeek());
  System.out.println(" old : " + feb_2015.format(DateTimeFormatter.ISO_DATE) + "     DOW :  "
    + feb_2015.getDayOfWeek() + "    new :  " + updateDate(feb_2015).format(DateTimeFormatter.ISO_DATE)
    + "     DOW :  " + updateDate(feb_2015).getDayOfWeek());
  System.out.println(" old : " + feb_2016.format(DateTimeFormatter.ISO_DATE) + "     DOW :  "
    + feb_2016.getDayOfWeek() + "    new :  " + updateDate(feb_2016).format(DateTimeFormatter.ISO_DATE)
    + "     DOW :  " + updateDate(feb_2016).getDayOfWeek());
  System.out.println(" old : " + feb_2017.format(DateTimeFormatter.ISO_DATE) + "     DOW :  "
    + feb_2017.getDayOfWeek() + "    new :   " + updateDate(feb_2017).format(DateTimeFormatter.ISO_DATE)
    + "    DOW :  " + updateDate(feb_2017).getDayOfWeek());
  System.out.println(" old : " + feb_2018.format(DateTimeFormatter.ISO_DATE) + "     DOW :  "
    + feb_2018.getDayOfWeek() + "    new :  " + updateDate(feb_2018).format(DateTimeFormatter.ISO_DATE)
    + "     DOW :  " + updateDate(feb_2018).getDayOfWeek());

 }

 public static LocalDateTime updateDate(LocalDateTime oldOdrDte) {

  int yearDiff = LocalDate.now().getYear() - oldOdrDte.getYear();
  int temp = yearDiff;
  if (yearDiff > 7)
   yearDiff = yearDiff % 7;
  if (temp > 7) {
   return (yearDiff < 4) ? oldOdrDte.plusDays((yearDiff * 365 - yearDiff) + (temp - yearDiff) * 365)
     : oldOdrDte.plusDays((yearDiff * 365 - (7 - yearDiff)) + (temp - yearDiff) * 365);

  } else {
   return oldOdrDte.plusDays((yearDiff < 4) ? (yearDiff * 365 - yearDiff) : (yearDiff * 365 + (7 - yearDiff)));
  }

 }

 public static LocalDateTime updateDate12(LocalDateTime oldOdrDte) {

  int yearDiff = LocalDate.now().getYear() - oldOdrDte.getYear();
  int temp = yearDiff;
  if (yearDiff > 7)
   yearDiff = yearDiff % 7;
  return oldOdrDte.plusDays((yearDiff < 4) ? (yearDiff * 365 - yearDiff) : (yearDiff * 365 + (7 - yearDiff)));
 }

}



Comments

Popular posts from this blog

GraphQL

What is GraphQL  API Standard invented & open-sourced by Facebook Alternative to  REST API  enables declarative data fetching  exposes single endpoint & responds to queries How it works?  Why Graphql? Improvises performance by reducing the data that is to be transferred over the internet Variety of different frontend frameworks and platforms on client-side Fast development speed & expectation for rapid feature development Why Graphql is better than REST? Flexibility & efficient  No more over /under fetching of data Over fetching : Under fetching: Insightful analytics  Schema serves as contract between client and server CORE CONCEPTS : SDL :SCHEMA DEFINITION LANGUAGE Writing Data with mutations 3 kinds of mutations creating new data updating existing data deleting existing data

The BattleGround

Last Sunday while zapping the channels of my idiot box I chanced upon to watch one of the greatest epic of our times –MAHABHARAT. It did’nt take me much time to recall the waves that it created across the nation- when it was telecasted for the first time.I was too young to comprehend it,yet I used to watch it with paramount interest,sitting next to dad & imitating his stimuli to what character speaks Later in my teens ,unlike most of my friends who used to enjoy watching top tens & horror shows , I was inundated to discover that zee was going to re telecast Mahabharat .This time, I was grown up enough to understand it,so I religiously watched all the episodes with same interest. Watching such an epic in formative years has great influence on one’s approach towards life .Today to me ,Mahabharat isn’t just another epic but it is a thinking process, where the mind is the battleground, THE KURUSHETRA ,where all kind of thoughts hover, the state of mind that we...

J2EE Design Patterns

Creational Design Pattern Creational:  Singleton when to use : Used in Logging, Cache, Session, Drivers  Creational:  Factory  When to use : Implementation : Factory chooses the objects, DAO, Abstract DAO factory  Creational: builder     Defines essiential parameter in constructor & optional in setters & add build method .Call build method at the end. Creational: Prototype     Creational:AbstractFactory   Structural   improves  the structure of code Structural:  prototype  Clone method  Structural: proxy  Structural: Facade  Structural: Composite Design Pattern   Structural: Flyweight Design Pattern Structural: Adapter   Structural: Bridge  Behavioural Behavioural:template  Subclass defines behvaiour , order of exectution can be defined in superclass     Behavioural:Observer  Subclass defines behvaiour , order of exectution can be defined in ...