This commit is contained in:
2019-09-01 15:21:42 +02:00
parent a083e412fd
commit 797062b8a9
26 changed files with 5154 additions and 5136 deletions

View File

@@ -1,123 +1,123 @@
/*
Copyright <20> 2005 - 2008 Annpoint, s.r.o.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-------------------------------------------------------------------------
NOTE: Reuse requires the following acknowledgement (see also NOTICE):
This product includes DayPilot (http://www.daypilot.org) developed by Annpoint, s.r.o.
*/
using System;
using System.Collections;
using System.Globalization;
using System.Text;
using System.Web;
namespace DayPilot.Utils
{
internal class Encoder
{
private static HttpApplication _app = null;
private static HttpServerUtility Server
{
get
{
if (HttpContext.Current != null)
return HttpContext.Current.Server;
if (_app == null)
_app = new HttpApplication();
return _app.Server;
}
}
internal static string HtmlEncode(string input)
{
if (input == null)
{
return null;
}
return Server.HtmlEncode(input);
}
internal static string UrlEncode(string input)
{
// return Server.UrlPathEncode(input);
if (input == null)
{
return null;
}
return input.Replace("&", "%26");
// return Server.UrlEncode(input);
}
internal static string UrlDecode(string input)
{
return Server.UrlDecode(input);
}
internal static DateTime UrlDecodeDateTime(string input)
{
CultureInfo culture = new CultureInfo("en-US");
string decoded = Server.UrlDecode(input);
try
{
return DateTime.ParseExact(decoded, culture.DateTimeFormat.SortableDateTimePattern, culture.DateTimeFormat);
}
catch (FormatException e)
{
throw new ApplicationException("Unable to parse DateTime: '" + decoded + "'.", e);
}
}
internal static string UrlEncode(IList list)
{
StringBuilder sb = new StringBuilder();
bool isFirst = true;
foreach (object o in list)
{
string item;
if (o is DateTime)
{
DateTime dt = (DateTime) o;
item = dt.ToString("s");
}
else if (o == null)
{
item = String.Empty;
}
else
{
item = o.ToString();
}
if (!isFirst)
{
sb.Append("&");
}
sb.Append(UrlEncode(item));
isFirst = false;
}
return sb.ToString();
}
}
}
/*
Copyright <20> 2005 - 2008 Annpoint, s.r.o.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-------------------------------------------------------------------------
NOTE: Reuse requires the following acknowledgement (see also NOTICE):
This product includes DayPilot (http://www.daypilot.org) developed by Annpoint, s.r.o.
*/
using System;
using System.Collections;
using System.Globalization;
using System.Text;
using System.Web;
namespace DayPilot.Utils
{
internal class Encoder
{
private static HttpApplication _app = null;
private static HttpServerUtility Server
{
get
{
if (HttpContext.Current != null)
return HttpContext.Current.Server;
if (_app == null)
_app = new HttpApplication();
return _app.Server;
}
}
internal static string HtmlEncode(string input)
{
if (input == null)
{
return null;
}
return Server.HtmlEncode(input);
}
internal static string UrlEncode(string input)
{
// return Server.UrlPathEncode(input);
if (input == null)
{
return null;
}
return input.Replace("&", "%26");
// return Server.UrlEncode(input);
}
internal static string UrlDecode(string input)
{
return Server.UrlDecode(input);
}
internal static DateTime UrlDecodeDateTime(string input)
{
CultureInfo culture = new CultureInfo("en-US");
string decoded = Server.UrlDecode(input);
try
{
return DateTime.ParseExact(decoded, culture.DateTimeFormat.SortableDateTimePattern, culture.DateTimeFormat);
}
catch (FormatException e)
{
throw new ApplicationException("Unable to parse DateTime: '" + decoded + "'.", e);
}
}
internal static string UrlEncode(IList list)
{
StringBuilder sb = new StringBuilder();
bool isFirst = true;
foreach (object o in list)
{
string item;
if (o is DateTime)
{
DateTime dt = (DateTime) o;
item = dt.ToString("s");
}
else if (o == null)
{
item = String.Empty;
}
else
{
item = o.ToString();
}
if (!isFirst)
{
sb.Append("&");
}
sb.Append(UrlEncode(item));
isFirst = false;
}
return sb.ToString();
}
}
}

View File

@@ -1,83 +1,83 @@
/*
Copyright <20> 2005 - 2008 Annpoint, s.r.o.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-------------------------------------------------------------------------
NOTE: Reuse requires the following acknowledgement (see also NOTICE):
This product includes DayPilot (http://www.daypilot.org) developed by Annpoint, s.r.o.
*/
using System;
using DayPilot.Web.Ui;
namespace DayPilot.Utils
{
/// <summary>
/// Helper class for hour formatting.
/// </summary>
public class TimeFormatter
{
/// <summary>
/// Extracts hour from DateTime class and formats it for 12/24 hours clock.
/// </summary>
/// <param name="time"></param>
/// <param name="clock"></param>
/// <param name="format"></param>
/// <returns></returns>
public static string GetHour(DateTime time, TimeFormat clock, string format)
{
return GetHour(time.Hour, clock, format);
}
/// <summary>
/// Formats an hour number for 12/24 hours clock.
/// </summary>
/// <param name="hour"></param>
/// <param name="clock"></param>
/// <param name="format"></param>
/// <returns></returns>
public static string GetHour(int hour, TimeFormat clock, string format)
{
bool am = (hour / 12) == 0;
if (clock == TimeFormat.Clock12Hours)
{
hour = hour % 12;
if (hour == 0)
hour = 12;
}
string suffix = String.Empty;
if (clock == TimeFormat.Clock12Hours)
{
if (am)
{
suffix = "AM";
}
else
{
suffix = "PM";
}
}
if (String.IsNullOrEmpty(format))
{
format = "{0} {1}";
}
return String.Format(format, hour, suffix);
}
}
}
/*
Copyright <20> 2005 - 2008 Annpoint, s.r.o.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-------------------------------------------------------------------------
NOTE: Reuse requires the following acknowledgement (see also NOTICE):
This product includes DayPilot (http://www.daypilot.org) developed by Annpoint, s.r.o.
*/
using System;
using DayPilot.Web.Ui;
namespace DayPilot.Utils
{
/// <summary>
/// Helper class for hour formatting.
/// </summary>
public class TimeFormatter
{
/// <summary>
/// Extracts hour from DateTime class and formats it for 12/24 hours clock.
/// </summary>
/// <param name="time"></param>
/// <param name="clock"></param>
/// <param name="format"></param>
/// <returns></returns>
public static string GetHour(DateTime time, TimeFormat clock, string format)
{
return GetHour(time.Hour, clock, format);
}
/// <summary>
/// Formats an hour number for 12/24 hours clock.
/// </summary>
/// <param name="hour"></param>
/// <param name="clock"></param>
/// <param name="format"></param>
/// <returns></returns>
public static string GetHour(int hour, TimeFormat clock, string format)
{
bool am = (hour / 12) == 0;
if (clock == TimeFormat.Clock12Hours)
{
hour = hour % 12;
if (hour == 0)
hour = 12;
}
string suffix = String.Empty;
if (clock == TimeFormat.Clock12Hours)
{
if (am)
{
suffix = "AM";
}
else
{
suffix = "PM";
}
}
if (String.IsNullOrEmpty(format))
{
format = "{0} {1}";
}
return String.Format(format, hour, suffix);
}
}
}

View File

@@ -1,158 +1,158 @@
/*
Copyright <20> 2005 - 2008 Annpoint, s.r.o.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-------------------------------------------------------------------------
NOTE: Reuse requires the following acknowledgement (see also NOTICE):
This product includes DayPilot (http://www.daypilot.org) developed by Annpoint, s.r.o.
*/
using System;
using System.Collections;
using System.Threading;
namespace DayPilot.Utils
{
/// <summary>
/// Helper class for week manipulation and formatting.
/// </summary>
public class Week
{
/// <summary>
/// Gets the first day of this week. Based on current culture.
/// </summary>
/// <returns></returns>
public static DateTime FirstDayOfWeek()
{
return FirstDayOfWeek(DateTime.Today);
}
/// <summary>
/// Gets the first day of a week where day (parameter) belongs. Based on current culture.
/// </summary>
/// <returns></returns>
public static DateTime FirstDayOfWeek(DateTime day)
{
return FirstDayOfWeek(day, Thread.CurrentThread.CurrentCulture.DateTimeFormat.FirstDayOfWeek);
}
/// <summary>
/// Gets the first day of a week where day (parameter) belongs. weekStart (parameter) specifies the starting day of week.
/// </summary>
/// <returns></returns>
public static DateTime FirstDayOfWeek(DateTime day, DayOfWeek weekStarts)
{
DateTime d = day;
while (d.DayOfWeek != weekStarts)
{
d = d.AddDays(-1);
}
return d;
}
/// <summary>
/// Returns Monday of the week where day (parameter) belongs.
/// </summary>
/// <param name="day"></param>
/// <returns></returns>
public static DateTime FirstWorkingDayOfWeek(DateTime day)
{
return FirstDayOfWeek(day, DayOfWeek.Monday);
}
// http://konsulent.sandelien.no/VB_help/Week/
// just for Monday being the first day of week
/// <summary>
/// Calculates week number for the specified date according to ISO 8601.
/// </summary>
/// <param name="date"></param>
/// <returns></returns>
public static int WeekNrISO8601(DateTime date)
{
bool ThursdayFlag = false;
int DayOfYear = date.DayOfYear;
int StartWeekDayOfYear =
(int)(new DateTime(date.Year, 1, 1)).DayOfWeek;
int EndWeekDayOfYear =
(int)(new DateTime(date.Year, 12, 31)).DayOfWeek;
if (StartWeekDayOfYear == 0)
StartWeekDayOfYear = 7;
if (EndWeekDayOfYear == 0)
EndWeekDayOfYear = 7;
int DaysInFirstWeek = 8 - (StartWeekDayOfYear);
if (StartWeekDayOfYear == 4 || EndWeekDayOfYear == 4)
ThursdayFlag = true;
int FullWeeks = (int)Math.Ceiling((DayOfYear - (DaysInFirstWeek)) / 7.0);
int WeekNumber = FullWeeks;
if (DaysInFirstWeek >= 4)
WeekNumber = WeekNumber + 1;
if (WeekNumber > 52 && !ThursdayFlag)
WeekNumber = 1;
if (WeekNumber == 0)
WeekNumber = WeekNrISO8601(new DateTime(date.Year - 1, 12, 31));
return WeekNumber;
}
/// <summary>
/// Returns day names (using current culture).
/// </summary>
/// <returns></returns>
public static ArrayList GetDayNames()
{
return GetDayNames("dddd");
}
/// <summary>
/// Returns day names (using current culture).
/// </summary>
/// <param name="format">Corresponds to DateTime.ToString() formats. "DD" is also available (first two characters of short day name).</param>
/// <returns></returns>
public static ArrayList GetDayNames(string format)
{
ArrayList result = new ArrayList();
DateTime start = new DateTime(2006, 12, 31); // Sunday
for (int i = 0; i < 7; i++)
{
// this uses the current culture
string name;
if (format == "DD")
{
name = start.AddDays(i).ToString("ddd").Substring(0, 2);
}
else
{
name = start.AddDays(i).ToString(format);
}
result.Add(name);
}
return result;
}
}
}
/*
Copyright <20> 2005 - 2008 Annpoint, s.r.o.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-------------------------------------------------------------------------
NOTE: Reuse requires the following acknowledgement (see also NOTICE):
This product includes DayPilot (http://www.daypilot.org) developed by Annpoint, s.r.o.
*/
using System;
using System.Collections;
using System.Threading;
namespace DayPilot.Utils
{
/// <summary>
/// Helper class for week manipulation and formatting.
/// </summary>
public class Week
{
/// <summary>
/// Gets the first day of this week. Based on current culture.
/// </summary>
/// <returns></returns>
public static DateTime FirstDayOfWeek()
{
return FirstDayOfWeek(DateTime.Today);
}
/// <summary>
/// Gets the first day of a week where day (parameter) belongs. Based on current culture.
/// </summary>
/// <returns></returns>
public static DateTime FirstDayOfWeek(DateTime day)
{
return FirstDayOfWeek(day, Thread.CurrentThread.CurrentCulture.DateTimeFormat.FirstDayOfWeek);
}
/// <summary>
/// Gets the first day of a week where day (parameter) belongs. weekStart (parameter) specifies the starting day of week.
/// </summary>
/// <returns></returns>
public static DateTime FirstDayOfWeek(DateTime day, DayOfWeek weekStarts)
{
DateTime d = day;
while (d.DayOfWeek != weekStarts)
{
d = d.AddDays(-1);
}
return d;
}
/// <summary>
/// Returns Monday of the week where day (parameter) belongs.
/// </summary>
/// <param name="day"></param>
/// <returns></returns>
public static DateTime FirstWorkingDayOfWeek(DateTime day)
{
return FirstDayOfWeek(day, DayOfWeek.Monday);
}
// http://konsulent.sandelien.no/VB_help/Week/
// just for Monday being the first day of week
/// <summary>
/// Calculates week number for the specified date according to ISO 8601.
/// </summary>
/// <param name="date"></param>
/// <returns></returns>
public static int WeekNrISO8601(DateTime date)
{
bool ThursdayFlag = false;
int DayOfYear = date.DayOfYear;
int StartWeekDayOfYear =
(int)(new DateTime(date.Year, 1, 1)).DayOfWeek;
int EndWeekDayOfYear =
(int)(new DateTime(date.Year, 12, 31)).DayOfWeek;
if (StartWeekDayOfYear == 0)
StartWeekDayOfYear = 7;
if (EndWeekDayOfYear == 0)
EndWeekDayOfYear = 7;
int DaysInFirstWeek = 8 - (StartWeekDayOfYear);
if (StartWeekDayOfYear == 4 || EndWeekDayOfYear == 4)
ThursdayFlag = true;
int FullWeeks = (int)Math.Ceiling((DayOfYear - (DaysInFirstWeek)) / 7.0);
int WeekNumber = FullWeeks;
if (DaysInFirstWeek >= 4)
WeekNumber = WeekNumber + 1;
if (WeekNumber > 52 && !ThursdayFlag)
WeekNumber = 1;
if (WeekNumber == 0)
WeekNumber = WeekNrISO8601(new DateTime(date.Year - 1, 12, 31));
return WeekNumber;
}
/// <summary>
/// Returns day names (using current culture).
/// </summary>
/// <returns></returns>
public static ArrayList GetDayNames()
{
return GetDayNames("dddd");
}
/// <summary>
/// Returns day names (using current culture).
/// </summary>
/// <param name="format">Corresponds to DateTime.ToString() formats. "DD" is also available (first two characters of short day name).</param>
/// <returns></returns>
public static ArrayList GetDayNames(string format)
{
ArrayList result = new ArrayList();
DateTime start = new DateTime(2006, 12, 31); // Sunday
for (int i = 0; i < 7; i++)
{
// this uses the current culture
string name;
if (format == "DD")
{
name = start.AddDays(i).ToString("ddd").Substring(0, 2);
}
else
{
name = start.AddDays(i).ToString(format);
}
result.Add(name);
}
return result;
}
}
}