BrightSide Workbench Full Report + Source Code
EventDates.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2020 Lluis TurrĂ³ Cutiller <http://www.turro.org/>
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU Affero General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU Affero General Public License for more details.
14  *
15  * You should have received a copy of the GNU Affero General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 package org.turro.elephant.calendar;
20 
21 import java.util.Date;
22 import org.amic.util.date.CheckDate;
23 import org.turro.elephant.context.Application;
24 import org.turro.i18n.I_;
25 
30 public class EventDates {
31 
32  //"lYesterdayCallFmt" Yesterday, at %1$tR
33  //"lTodayCallFmt" Today, at %1$tR
34  //"lTomorrowCallFmt" Tomorrow, at %1$tR
35  //"lSingleDayCallFmt" %1$tA, %1$te of %1$tB %1$tY at %1$tR
36 
37  public static String eventFormat(Date date) {
38  CheckDate cdDate = new CheckDate(date);
39  Date now = new Date();
40  if(cdDate.sameDay(now)) {
41  return String.format(Application.getUsedLocale(), "%s, %s %3$tR",
42  I_.get("Today"), I_.get("At"),
43  cdDate.getCalendar());
44  } else if(cdDate.addDays(1).sameDay(now)) {
45  return String.format(Application.getUsedLocale(), "%s, %s %3$tR",
46  I_.get("Tomorrow"), I_.get("At"),
47  cdDate.getCalendar());
48  } else if(cdDate.addDays(-1).sameDay(now)) {
49  return String.format(Application.getUsedLocale(), "%s, %s %3$tR",
50  I_.get("Yesterday"), I_.get("At"),
51  cdDate.getCalendar());
52  } else {
53  return String.format(Application.getUsedLocale(), "%2$tA, %2$td/%2$tm/%2$ty %s %2$tR",
54  I_.get("At"),
55  cdDate.getCalendar());
56  }
57  }
58 
59  public static String eventFormat(CheckDate start, String format) {
60  return String.format(Application.getUsedLocale(), format, start.getCalendar());
61  }
62 
63  //"lSingleDayEvtFmt" %1$tA, %1$te of %1$tB %1$tY from %1$tR to %2$tR
64  //"lMultipleDayEvtFmt" From %1$td/%1$tm/%1$ty at %1$tR to %2$td/%2$tm/%2$ty at %2$tR
65  //"lSingleDayWithYearEvtFmt" %1$tA, %1$td/%1$tm/%1$ty from %1$tR to %2$tR
66  //"lMultipleDayWithYearEvtFmt" From %1$td/%1$tm/%1$ty at %1$tR to %2$td/%2$tm/%2$ty at %2$tR
67  //"lYesterdayEvtFmt" Yesterday, from %1$tR to %2$tR
68  //"lTodayEvtFmt" Today, from %1$tR to %2$tR
69  //"lTomorrowEvtFmt" Tomorrow, from %1$tR to %2$tR
70 
71  public static String eventFormat(Date start, Date end) {
72  CheckDate cdStart = new CheckDate(start),
73  cdEnd = new CheckDate(end);
74  Date now = new Date();
75  if(cdStart.sameDay(end)) {
76  if(cdStart.sameDay(now)) {
77  return String.format(Application.getUsedLocale(), "%s, %s %4$tR %s %5$tR",
78  I_.get("Today"),
79  I_.get("At"), I_.get("To"),
80  cdStart.getCalendar(), cdEnd.getCalendar());
81  } else if(cdStart.addDays(1).sameDay(now)) {
82  return String.format(Application.getUsedLocale(), "%s, %s %4$tR %s %5$tR",
83  I_.get("Tomorrow"),
84  I_.get("At"), I_.get("To"),
85  cdStart.getCalendar(), cdEnd.getCalendar());
86  } else if(cdStart.addDays(-1).sameDay(now)) {
87  return String.format(Application.getUsedLocale(), "%s, %s %4$tR %s %5$tR",
88  I_.get("Yesterday"),
89  I_.get("At"), I_.get("To"),
90  cdStart.getCalendar(), cdEnd.getCalendar());
91  } else {
92  return String.format(Application.getUsedLocale(), "%3$tA, %3$td/%3$tm/%3$ty %s %3$tR %s %4$tR",
93  I_.get("At"), I_.get("To"),
94  cdStart.getCalendar(), cdEnd.getCalendar());
95  }
96  } else {
97  return String.format(Application.getUsedLocale(), "%s %3$td/%3$tm/%3$ty %3$tR %s %4$td/%4$tm/%4$ty %4$tR",
98  I_.get("From"), I_.get("To"),
99  cdStart.getCalendar(), cdEnd.getCalendar());
100  }
101  }
102 
103  public static String eventFormat(CheckDate start, CheckDate end, String format) {
104  return String.format(Application.getUsedLocale(), format, start.getCalendar(), end.getCalendar());
105  }
106 
107  private EventDates() {
108  }
109 
110 }
static String eventFormat(CheckDate start, CheckDate end, String format)
static String eventFormat(Date date)
Definition: EventDates.java:37
static String eventFormat(CheckDate start, String format)
Definition: EventDates.java:59
static String eventFormat(Date start, Date end)
Definition: EventDates.java:71
static String get(String msg)
Definition: I_.java:41