Notes
![]() ![]() Notes - notes.io |
package com.adventnet.la;
import java.text.ParseException;
import java.util.Calendar;
import java.util.TimeZone;
import java.util.logging.Logger;
import com.adventnet.la.util.DateFormatUtil;
public class TimePack
{
private static Logger logger = Logger.getLogger(TimePack.class.toString());
private String timeFrame="CustomTime";//No I18N
private String startDate;
private String endDate;
private Calendar calendar;
private long startTimeInLong = 0;
private long endTimeInLong = 0;
private TimeZone timeZone;
public TimePack(TimeZone timeZone) {
this.timeZone = timeZone;
calculateDates();
}
public TimePack(String timeFrame,TimeZone timeZone) {
this.timeFrame = timeFrame;
this.timeZone = timeZone;
calculateDates();
}
public TimePack(String startDate,String endDate,TimeZone timeZone) {
this.startDate = startDate;
this.endDate = endDate;
this.timeZone = timeZone;
calculateDates();
}
public TimePack(String startDate,String endDate)
{
this.startDate = startDate;
this.endDate = endDate;
this.timeZone = TimeZone.getDefault();
calculateDates();
}
public String getTimeFrame()
{
return this.timeFrame;
}
public String getStartDate()
{
return this.startDate;
}
public String getEndDate()
{
return this.endDate;
}
public long getStartTimeInLong()
{
return this.startTimeInLong;
}
public long getEndTimeInLong()
{
return this.endTimeInLong;
}
public TimeZone getTimeZone() {
return this.timeZone;
}
private void calculateToday()
{
calendar.set(Calendar.SECOND,0);
calendar.set(Calendar.MILLISECOND,0);
//this is to get 5:35 from 5:32
int minute = calendar.get(Calendar.MINUTE);
calendar.add(Calendar.MINUTE,(5-minute%5));
this.endTimeInLong = calendar.getTimeInMillis();
this.endDate = DateFormatUtil.getCalendarDateString(calendar.getTime(), timeZone);
calendar.set(Calendar.MINUTE,0);
calendar.set(Calendar.HOUR_OF_DAY,0);
this.startTimeInLong = calendar.getTimeInMillis();
this.startDate = DateFormatUtil.getCalendarDateString(calendar.getTime(), timeZone);
}
private String currentTime;
public String getCurrentTime() {
return this.currentTime;
}
private void calculateDates()
{
logger.fine("calculateDates:"+timeFrame+","+startDate+","+endDate);
logger.fine("zones:"+TimeZone.getDefault()+","+timeZone);
calendar = Calendar.getInstance(timeZone);
this.currentTime = DateFormatUtil.getCalendarDateString(calendar.getTime(), timeZone);
if("CustomTime".equals(timeFrame)) {
if(startDate==null || endDate==null) {
calculateToday();
} else {
try {
this.startTimeInLong = DateFormatUtil.getCalendarDate(startDate, timeZone).getTime();
this.endTimeInLong = DateFormatUtil.getCalendarDate(endDate, timeZone).getTime();
} catch (ParseException e) {
e.printStackTrace();
}
}
}
else if("LastDay".equals(timeFrame))
{
this.endDate = DateFormatUtil.getCalendarDateString(calendar.getTime(), timeZone);
this.endTimeInLong = calendar.getTime().getTime();
calendar.add(Calendar.DAY_OF_MONTH,-1);
this.startDate = DateFormatUtil.getCalendarDateString(calendar.getTime(), timeZone);
this.startTimeInLong = calendar.getTime().getTime();
}
else if("LastHour".equals(timeFrame))
{
this.endDate = DateFormatUtil.getCalendarDateString(calendar.getTime(), timeZone);
this.endTimeInLong = calendar.getTime().getTime();
calendar.add(Calendar.HOUR,-1);
this.startDate = DateFormatUtil.getCalendarDateString(calendar.getTime(), timeZone);
this.startTimeInLong = calendar.getTime().getTime();
}
else if("LastWeek".equals(timeFrame))
{
this.endDate = DateFormatUtil.getCalendarDateString(calendar.getTime(), timeZone);
this.endTimeInLong = calendar.getTime().getTime();
calendar.add(Calendar.WEEK_OF_MONTH,-1);
this.startDate = DateFormatUtil.getCalendarDateString(calendar.getTime(), timeZone);
this.startTimeInLong = calendar.getTime().getTime();
}
else if("LastMonth".equals(timeFrame))
{
this.endDate = DateFormatUtil.getCalendarDateString(calendar.getTime(), timeZone);
this.endTimeInLong = calendar.getTime().getTime();
calendar.add(Calendar.MONTH,-1);
this.startDate = DateFormatUtil.getCalendarDateString(calendar.getTime(), timeZone);
this.startTimeInLong = calendar.getTime().getTime();
}
else if("LastQuarter".equals(timeFrame))
{
this.endDate = DateFormatUtil.getCalendarDateString(calendar.getTime(), timeZone);
this.endTimeInLong = calendar.getTime().getTime();
calendar.add(Calendar.MONTH,-3);
this.startDate = DateFormatUtil.getCalendarDateString(calendar.getTime(), timeZone);
this.startTimeInLong = calendar.getTime().getTime();
}
logger.fine(startDate+","+endDate+","+startTimeInLong+","+endTimeInLong+","+currentTime);
}
}
![]() |
Notes is a web-based application for online taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000+ notes created and continuing...
With notes.io;
- * You can take a note from anywhere and any device with internet connection.
- * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
- * You can quickly share your contents without website, blog and e-mail.
- * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
- * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.
Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.
Easy: Notes.io doesn’t require installation. Just write and share note!
Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )
Free: Notes.io works for 14 years and has been free since the day it was started.
You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;
Email: [email protected]
Twitter: http://twitter.com/notesio
Instagram: http://instagram.com/notes.io
Facebook: http://facebook.com/notesio
Regards;
Notes.io Team