package net.resheim.eclipse.timekeeper.ui;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.time.temporal.WeekFields;
import java.util.Locale;

import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.osgi.framework.BundleContext;

/**
 * The activator class controls the plug-in life cycle
 */
public class Activator extends AbstractUIPlugin {

	// The plug-in ID
	public static final String PLUGIN_ID = "net.resheim.eclipse.timekeeper.ui"; //$NON-NLS-1$

	// The shared instance
	private static Activator plugin;
	
	/**
	 * The constructor
	 */
	public Activator() {
	}

	/*
	 * (non-Javadoc)
	 * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
	 */
	public void start(BundleContext context) throws Exception {
		super.start(context);
		plugin = this;
	}

	/*
	 * (non-Javadoc)
	 * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
	 */
	public void stop(BundleContext context) throws Exception {
		plugin = null;
		super.stop(context);
	}

	/**
	 * Returns the shared instance
	 *
	 * @return the shared instance
	 */
	public static Activator getDefault() {
		return plugin;
	}

	/**
	 * Returns an image descriptor for the image file at the given
	 * plug-in relative path
	 *
	 * @param path the path
	 * @return the image descriptor
	 */
	public static ImageDescriptor getImageDescriptor(String path) {
		return imageDescriptorFromPlugin(PLUGIN_ID, path);
	}
	
	private DateTimeFormatter formatter = DateTimeFormatter.ofPattern("EEE d");;

	public String[] getHeadings(LocalDate date){
		String[] headings = new String[7];
		WeekFields weekFields = WeekFields.of(Locale.getDefault());
		// Current day in the week
		int day = date.get(weekFields.dayOfWeek());
		// First date of the week
		LocalDate first = date.minusDays(day - 1);
		for (int i=0;i<7;i++){
			headings[i] = formatter.format(first);
			first = first.plusDays(1);
		}
		return headings;
	}
	
}

@@ -595,17 +595,16 @@
 plugin;%0A
-%09
 %0A%09/**%0A%09 
@@ -670,36 +670,45 @@
 on-Javadoc)%0A%09 * 
-@see
+%0A%09 * @see%0A%09 *
  org.eclipse.ui.
@@ -761,39 +761,55 @@
 rk.BundleContext
+%0A%09 * 
 )%0A%09 */%0A
+%09@Override%0A
 %09public void sta
@@ -924,20 +924,29 @@
 oc)%0A%09 * 
-@see
+%0A%09 * @see%0A%09 *
  org.ecl
@@ -1014,23 +1014,39 @@
 eContext
+%0A%09 * 
 )%0A%09 */%0A
+%09@Override%0A
 %09public 
@@ -1352,20 +1352,16 @@
 iven
-%0A%09 *
  plug-in
  rel
@@ -1356,16 +1356,20 @@
  plug-in
+%0A%09 *
  relativ
@@ -1394,16 +1394,31 @@
 ram path
+%0A%09 *           
  the pat
@@ -1578,17 +1578,16 @@
 th);%0A%09%7D%0A
-%09
 %0A%09privat
@@ -1588,16 +1588,22 @@
 private 
+final 
 DateTime
@@ -1664,11 +1664,276 @@
  d%22)
-;;%0A
+.withLocale(Locale.US);%0A%0A%09/**%0A%09 * Returns a list of weekday names and dates, using the default locale to%0A%09 * determine the first day of the week (Sunday or Monday).%0A%09 *%0A%09 * @param date%0A%09 *            starting date%0A%09 * @return an array with weekday names and dates%0A%09 */
 %0A%09pu
@@ -1973,16 +1973,17 @@
 te date)
+ 
 %7B%0A%09%09Stri
@@ -2239,19 +2239,26 @@
 nt i
-=0;i%3C
+ = 0; i %3C 
 7;
+ 
 i++)
+ 
 %7B%0A%09%09
@@ -2353,12 +2353,11 @@
 ngs;%0A%09%7D%0A
-%09
 %0A%7D%0A

Improve weekday formatting.