You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by pu...@apache.org on 2012/11/27 03:07:31 UTC
[22/30] git commit: globalization api support
globalization api support
Project: http://git-wip-us.apache.org/repos/asf/cordova-wp8/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-wp8/commit/880e2f3b
Tree: http://git-wip-us.apache.org/repos/asf/cordova-wp8/tree/880e2f3b
Diff: http://git-wip-us.apache.org/repos/asf/cordova-wp8/diff/880e2f3b
Branch: refs/heads/master
Commit: 880e2f3be7aa079acd898690464dea0ee9e59681
Parents: ed5ad77
Author: sgrebnov <se...@gmail.com>
Authored: Thu Nov 15 14:02:46 2012 +0400
Committer: sgrebnov <se...@gmail.com>
Committed: Thu Nov 15 14:02:46 2012 +0400
----------------------------------------------------------------------
plugins/CordovaPlugins.csproj | 3 +
plugins/www/master.css | 13 +-
plugins/www/plugins/Globalization/Globalization.cs | 1176 +++++++++++++++
plugins/www/plugins/Globalization/global.html | 143 ++
plugins/www/plugins/Globalization/globalization.js | 540 +++++++
plugins/www/plugins/index.html | 1 +
6 files changed, 1872 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-wp8/blob/880e2f3b/plugins/CordovaPlugins.csproj
----------------------------------------------------------------------
diff --git a/plugins/CordovaPlugins.csproj b/plugins/CordovaPlugins.csproj
index 69487a0..0499980 100644
--- a/plugins/CordovaPlugins.csproj
+++ b/plugins/CordovaPlugins.csproj
@@ -130,6 +130,7 @@
</Compile>
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="www\plugins\ChildBrowser\ChildBrowserCommand.cs" />
+ <Compile Include="www\plugins\Globalization\Globalization.cs" />
<Compile Include="www\plugins\LiveTiles\LiveTiles.cs" />
<Compile Include="www\plugins\PGMapLauncher\PGMapLauncher.cs" />
<Compile Include="www\plugins\PGSocialShare\PGSocialShare.cs" />
@@ -159,6 +160,8 @@
<Content Include="www\plugins\ChildBrowser\ChildBrowser.js" />
<Content Include="www\plugins\Facebook\facebook.html" />
<Content Include="www\plugins\Facebook\FBConnect.js" />
+ <Content Include="www\plugins\Globalization\globalization.js" />
+ <Content Include="www\plugins\Globalization\global.html" />
<Content Include="www\plugins\index.html" />
<Content Include="www\plugins\LiveTiles\liveTiles.js" />
<Content Include="www\plugins\LiveTiles\liveTilesExample.html">
http://git-wip-us.apache.org/repos/asf/cordova-wp8/blob/880e2f3b/plugins/www/master.css
----------------------------------------------------------------------
diff --git a/plugins/www/master.css b/plugins/www/master.css
index 2a9002d..536cf39 100644
--- a/plugins/www/master.css
+++ b/plugins/www/master.css
@@ -11,7 +11,7 @@
/**
-main wp7 color and fonts
+main wp color and fonts
*/
@@ -84,7 +84,7 @@ a.btn, div.btn
margin:3px 0px 3px 5px;
}
-a.backBtn, input[type="button"], input[type="submit"]
+a.backBtn, input[type="button"], input[type="submit"], button
{
background: Background;
color: Highlight;
@@ -99,18 +99,23 @@ a.backBtn, input[type="button"], input[type="submit"]
}
-input[type="button"] {
+input[type="button"], button {
display:block;
margin:10px 0px;
font-size: 15px;
}
-input[type="button"]:active, input[type="submit"]:active
+input[type="button"]:active, input[type="submit"]:active, button:active
{
background: white;
color: black;
}
+button {
+ width: 95%;
+ margin: 10px 6px;
+}
+
/**
Input fields
http://git-wip-us.apache.org/repos/asf/cordova-wp8/blob/880e2f3b/plugins/www/plugins/Globalization/Globalization.cs
----------------------------------------------------------------------
diff --git a/plugins/www/plugins/Globalization/Globalization.cs b/plugins/www/plugins/Globalization/Globalization.cs
new file mode 100644
index 0000000..f3428b6
--- /dev/null
+++ b/plugins/www/plugins/Globalization/Globalization.cs
@@ -0,0 +1,1176 @@
+/*
+ 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.
+*/
+
+using System;
+using System.Globalization;
+using System.Runtime.Serialization;
+
+namespace WPCordovaClassLib.Cordova.Commands
+{
+ /// <summary>
+ /// Provides information about system locale, culture settings, number formats, ect.
+ /// </summary>
+ public class Globalization : BaseCommand
+ {
+
+ #region Globalization errors
+
+ /// <summary>
+ /// Globalization error codes.
+ /// </summary>
+ public enum ErrorCode : int
+ {
+ UnknownError = 0,
+ FormattingError = 1,
+ ParsingError = 2,
+ PatternError = 3
+ }
+
+ /// <summary>
+ /// Represents globalization error object.
+ /// </summary>
+ [DataContract]
+ public class GlobalizationError
+ {
+ #region Error messages
+ /// <summary>
+ /// Error messages
+ /// </summary>
+ public const string UnknownError = "UNKNOWN_ERROR";
+ public const string FormattingError = "FORMATTIN_ERROR";
+ public const string ParsingError = "PARSING_ERROR";
+ public const string PatternError = "PATTERN_ERROR";
+
+ #endregion
+
+ /// <summary>
+ /// Error code
+ /// </summary>
+ [DataMember(Name = "code", IsRequired = false)]
+ public ErrorCode Code { get; set; }
+
+ /// <summary>
+ /// Error message
+ /// </summary>
+ [DataMember(Name = "message", IsRequired = false)]
+ public string Message { get; set; }
+
+ /// <summary>
+ /// Default constructor
+ /// </summary>
+ public GlobalizationError()
+ {
+ this.Code = ErrorCode.UnknownError;
+ this.Message = UnknownError;
+ }
+
+ /// <summary>
+ /// Constructor setting error code
+ /// </summary>
+ public GlobalizationError(ErrorCode error)
+ {
+ this.Code = error;
+
+ switch (error)
+ {
+ case ErrorCode.ParsingError:
+ {
+ this.Message = ParsingError;
+ break;
+ }
+ case ErrorCode.FormattingError:
+ {
+ this.Message = FormattingError;
+ break;
+ }
+ case ErrorCode.PatternError:
+ {
+ this.Message = PatternError;
+ break;
+ }
+ default:
+ {
+ this.Message = UnknownError;
+ break;
+ }
+ }
+ }
+ }
+
+ #endregion
+
+ #region Globalization options
+
+ /// <summary>
+ /// Represents globalization options.
+ /// </summary>
+ [DataContract]
+ public class GlobalizationOptions
+ {
+ #region available option values
+ /// <summary>
+ /// Number pattern types.
+ /// </summary>
+ public const string Percent = "percent";
+ public const string Currency = "currency";
+ public const string Decimal = "decimal";
+
+ /// <summary>
+ /// Format length types
+ /// </summary>
+ public const string Short = "short";
+ public const string Medium = "medium";
+ public const string Long = "long";
+ public const string Full = "full";
+
+ /// <summary>
+ /// Selector types
+ /// </summary>
+ public const string TimeSelector = "time";
+ public const string DateSelector = "date";
+ public const string DateAndTimeSelector = "date and time";
+
+ /// <summary>
+ /// Date name types
+ /// </summary>
+ public const string Narrow = "narrow";
+ public const string Wide = "wide";
+
+ /// <summary>
+ /// Date name items
+ /// </summary>
+ public const string Months = "months";
+ public const string Days = "days";
+
+ #endregion
+
+ /// <summary>
+ /// Additional options
+ /// </summary>
+ [DataMember(Name = "options", IsRequired = false)]
+ public Options AdditionalOptions {get; set;}
+
+ /// <summary>
+ /// Date to convert
+ /// </summary>
+ [DataMember(Name = "date", IsRequired = false)]
+ public long Date { get; set; }
+
+ /// <summary>
+ /// Date as stirng
+ /// </summary>
+ [DataMember(Name = "dateString", IsRequired = false)]
+ public string DateString { get; set; }
+
+ /// <summary>
+ /// Currency code
+ /// </summary>
+ [DataMember(Name = "currencyCode", IsRequired = false)]
+ public string CurrencyCode { get; set; }
+
+ /// <summary>
+ /// Number as string
+ /// </summary>
+ [DataMember(Name = "numberString", IsRequired = false)]
+ public string NumberString { get; set; }
+
+ /// <summary>
+ /// Number to convert
+ /// </summary>
+ [DataMember(Name = "number", IsRequired = false)]
+ public double Number { get; set; }
+ }
+
+ /// <summary>
+ /// Represents additional options
+ /// </summary>
+ [DataContract]
+ public class Options
+ {
+ /// <summary>
+ /// Pattern type
+ /// </summary>
+ [DataMember(Name = "type", IsRequired = false)]
+ public string Type { get; set; }
+
+ /// <summary>
+ /// Format length
+ /// </summary>
+ [DataMember(Name = "formatLength", IsRequired = false)]
+ public string FormatLength { get; set; }
+
+ /// <summary>
+ /// Selector
+ /// </summary>
+ [DataMember(Name = "selector", IsRequired = false)]
+ public string Selector { get; set; }
+
+ /// <summary>
+ /// Date name item
+ /// </summary>
+ [DataMember(Name = "item", IsRequired = false)]
+ public string Item { get; set; }
+ }
+
+ #endregion
+
+ #region returned objects
+
+ #region Number pattern object
+
+ /// <summary>
+ /// Represents number pattern
+ /// </summary>
+ [DataContract]
+ public class NumberPattern
+ {
+ /// <summary>
+ /// Pattern
+ /// </summary>
+ [DataMember(Name = "pattern", IsRequired = false)]
+ public string Pattern { get; set; }
+
+ /// <summary>
+ /// Symbol
+ /// </summary>
+ [DataMember(Name = "symbol", IsRequired = false)]
+ public string Symbol { get; set; }
+
+ /// <summary>
+ /// Fraction
+ /// </summary>
+ [DataMember(Name = "fraction", IsRequired = false)]
+ public int Fraction { get; set; }
+
+ /// <summary>
+ /// Positive
+ /// </summary>
+ [DataMember(Name = "positive", IsRequired = false)]
+ public string Positive { get; set; }
+
+ /// <summary>
+ /// Negative
+ /// </summary>
+ [DataMember(Name = "negative", IsRequired = false)]
+ public string Negative { get; set; }
+
+ /// <summary>
+ /// Rounding
+ /// </summary>
+ [DataMember(Name = "rounding", IsRequired = false)]
+ public int Rounding { get; set; }
+
+ /// <summary>
+ /// Decimal
+ /// </summary>
+ [DataMember(Name = "decimal", IsRequired = false)]
+ public string Decimal { get; set; }
+
+ /// <summary>
+ /// Grouping
+ /// </summary>
+ [DataMember(Name = "grouping", IsRequired = false)]
+ public string Grouping { get; set; }
+
+ /// <summary>
+ /// Constructor of the class
+ /// </summary>
+ /// <param name="pattern"></param>
+ /// <param name="symbol"></param>
+ /// <param name="fraction"></param>
+ /// <param name="positive"></param>
+ /// <param name="negative"></param>
+ /// <param name="rounding"></param>
+ /// <param name="dec"></param>
+ /// <param name="grouping"></param>
+ public NumberPattern(string pattern, string symbol, int fraction, string positive, string negative, int rounding, string dec, string grouping)
+ {
+ this.Pattern = pattern;
+ this.Symbol = symbol;
+ this.Fraction = fraction;
+ this.Positive = positive;
+ this.Negative = negative;
+ this.Rounding = rounding;
+ this.Decimal = dec;
+ this.Grouping = grouping;
+ }
+ }
+ #endregion
+
+ #region Date format object
+
+ /// <summary>
+ /// Represents date format
+ /// </summary>
+ [DataContract]
+ public class DateFormat
+ {
+ /// <summary>
+ /// Year
+ /// </summary>
+ [DataMember(Name = "year", IsRequired = false)]
+ public int Year { get; set; }
+
+ /// <summary>
+ /// Month
+ /// </summary>
+ [DataMember(Name = "month", IsRequired = false)]
+ public int Month { get; set; }
+
+ /// <summary>
+ /// Day
+ /// </summary>
+ [DataMember(Name = "day", IsRequired = false)]
+ public int Day { get; set; }
+
+ /// <summary>
+ /// Hour
+ /// </summary>
+ [DataMember(Name = "hour", IsRequired = false)]
+ public int Hour { get; set; }
+
+ /// <summary>
+ /// Minute
+ /// </summary>
+ [DataMember(Name = "minute", IsRequired = false)]
+ public int Minute { get; set; }
+
+ /// <summary>
+ /// Second
+ /// </summary>
+ [DataMember(Name = "second", IsRequired = false)]
+ public int Second { get; set; }
+
+ /// <summary>
+ /// Millisecond
+ /// </summary>
+ [DataMember(Name = "millisecond", IsRequired = false)]
+ public int Millisecond { get; set; }
+
+ public DateFormat(int year, int month, int day, int hour, int minute, int second, int millisecond)
+ {
+ this.Year = year;
+ this.Month = month;
+ this.Day = day;
+ this.Hour = hour;
+ this.Minute = minute;
+ this.Millisecond = millisecond;
+ }
+
+ }
+ #endregion
+
+ #region Date pattern object
+
+ /// <summary>
+ /// Represents date pattern object
+ /// </summary>
+ [DataContract]
+ public class DatePattern
+ {
+
+ /// <summary>
+ /// Date pattern
+ /// </summary>
+ [DataMember(Name = "pattern", IsRequired = false)]
+ public string Pattern { get; set; }
+
+ /// <summary>
+ /// TimeZone
+ /// </summary>
+ [DataMember(Name = "timezone", IsRequired = false)]
+ public string TimeZone { get; set; }
+
+ /// <summary>
+ /// UTC offset
+ /// </summary>
+ [DataMember(Name = "utc_offset", IsRequired = false)]
+ public double UtcOffset { get; set; }
+
+ /// <summary>
+ /// Dst offset
+ /// </summary>
+ [DataMember(Name = "dst_offset", IsRequired = false)]
+ public double DstOffset { get; set; }
+
+ /// <summary>
+ /// Constructor of the class
+ /// </summary>
+ /// <param name="pattern"></param>
+ /// <param name="timezone"></param>
+ /// <param name="utcOffset"></param>
+ /// <param name="dstOffset"></param>
+ public DatePattern(string pattern, string timezone, double utcOffset, double dstOffset)
+ {
+ this.Pattern = pattern;
+ this.TimeZone = timezone;
+ this.UtcOffset = utcOffset;
+ this.DstOffset = dstOffset;
+ }
+
+ }
+
+ #endregion
+
+ #endregion
+
+ #region Locale info
+
+ /// <summary>
+ /// Gets the string identifier for the client's current locale setting.
+ /// </summary>
+ /// <param name="options"></param>
+ public void getLocaleName(string options)
+ {
+ try
+ {
+ var locale = RegionInfo.CurrentRegion.TwoLetterISORegionName;
+ PluginResult result = new PluginResult(PluginResult.Status.OK, this.WrapIntoJSON(locale));
+ this.DispatchCommandResult(result);
+ }
+ catch(Exception e)
+ {
+ this.DispatchCommandResult(new PluginResult(PluginResult.Status.ERROR, new GlobalizationError()));
+ }
+ }
+
+ /// <summary>
+ /// Gets the string identifier for the client's current language.
+ /// </summary>
+ /// <param name="options"></param>
+ public void getPreferredLanguage(string options)
+ {
+ try
+ {
+ var language = CultureInfo.CurrentCulture.TwoLetterISOLanguageName;
+ PluginResult result = new PluginResult(PluginResult.Status.OK, this.WrapIntoJSON(language));
+ this.DispatchCommandResult(result);
+ }
+ catch (Exception e)
+ {
+ this.DispatchCommandResult(new PluginResult(PluginResult.Status.ERROR, new GlobalizationError()));
+ }
+ }
+
+ #endregion
+
+ #region Date and time info
+
+ /// <summary>
+ /// Gets whether daylight savings time is in effect for a given date using the client's
+ /// time zone and calendar.
+ /// </summary>
+ /// <param name="opitons">Date to daylight savings check.</param>
+ public void isDayLightSavingsTime(string options)
+ {
+ GlobalizationOptions globalOptions;
+
+ try
+ {
+ string[] args = JSON.JsonHelper.Deserialize<string[]>(options);
+ globalOptions = JSON.JsonHelper.Deserialize<GlobalizationOptions>(args[0]);
+ }
+ catch (Exception e)
+ {
+ DispatchCommandResult(new PluginResult(PluginResult.Status.JSON_EXCEPTION));
+ return;
+ }
+
+ try
+ {
+ DateTime start = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
+ DateTime date = start.AddMilliseconds(globalOptions.Date).ToLocalTime();
+ TimeZoneInfo localZone = TimeZoneInfo.Local;
+ bool isDaylightSavingTime = localZone.IsDaylightSavingTime(date);
+ this.DispatchCommandResult(new PluginResult(PluginResult.Status.OK, this.WrapIntoJSON(isDaylightSavingTime, "dst")));
+ }
+ catch (Exception e)
+ {
+ this.DispatchCommandResult(new PluginResult(PluginResult.Status.ERROR, new GlobalizationError()));
+ }
+ }
+
+ /// <summary>
+ /// Gets the first day of the week according to the client's user preferences and calendar.
+ /// The days of the week are numbered starting from 1 where 1 is considered to be Sunday.
+ /// </summary>
+ /// <param name="options"></param>
+ public void getFirstDayOfWeek(string options)
+ {
+ try
+ {
+ // DateTimeFormat returns days of the week numbered from zero, so we have to increase returned value by one.
+ var firstDayOfWeek = (int)CultureInfo.CurrentCulture.DateTimeFormat.FirstDayOfWeek + 1;
+ PluginResult result = new PluginResult(PluginResult.Status.OK, this.WrapIntoJSON(firstDayOfWeek));
+ this.DispatchCommandResult(result);
+ }
+ catch (Exception e)
+ {
+ this.DispatchCommandResult(new PluginResult(PluginResult.Status.ERROR, new GlobalizationError()));
+ }
+ }
+
+ #endregion
+
+ #region Formatting
+
+ /// <summary>
+ /// Gets a date formatted as a string according to the client's user preferences and calendar using the time zone of the client.
+ /// </summary>
+ /// <param name="options"></param>
+ public void dateToString(string options)
+ {
+ GlobalizationOptions globalOptions;
+
+ try
+ {
+ string[] args = JSON.JsonHelper.Deserialize<string[]>(options);
+ globalOptions = JSON.JsonHelper.Deserialize<GlobalizationOptions>(args[0]);
+ }
+ catch (Exception e)
+ {
+ DispatchCommandResult(new PluginResult(PluginResult.Status.JSON_EXCEPTION));
+ return;
+ }
+
+ try
+ {
+ DateTime start = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
+ DateTime date = start.AddMilliseconds(globalOptions.Date).ToLocalTime();
+
+ string format = "{0:M/dd/yy H:m:s}"; //short datetime by default
+ int formatLength = 0; //default format
+ int selector = 0; //default selector
+
+ if (globalOptions.AdditionalOptions != null)
+ {
+ if (globalOptions.AdditionalOptions.FormatLength != null)
+ {
+ string t = globalOptions.AdditionalOptions.FormatLength;
+
+ if (t.Equals(GlobalizationOptions.Full))
+ {
+ formatLength++;
+ }
+ }
+
+ if (globalOptions.AdditionalOptions.Selector != null)
+ {
+ string t = globalOptions.AdditionalOptions.Selector;
+
+ if (t.Equals(GlobalizationOptions.DateSelector))
+ {
+ selector += 10;
+ }
+ else if (t.Equals(GlobalizationOptions.TimeSelector))
+ {
+ selector += 20;
+ }
+ }
+
+ //determine return value
+ int method = formatLength + selector;
+
+ switch (method)
+ {
+ case 1: // full datetime
+ {
+ format = "{0:MMMM/dddd/yyyy HH:mm:ss tt}";
+ break;
+ }
+ case 10: // short date
+ {
+ format = "{0:d}";
+ break;
+ }
+ case 11: // full date
+ {
+ format = "{0:D}";
+ break;
+ }
+ case 20: // short time
+ {
+ format = "{0:t}";
+ break;
+ }
+ case 21: // full time
+ {
+ format = "{0:T}";
+ break;
+ }
+ default: // short datetime
+ {
+ format = "{0:M/dd/yy H:m:s}";
+ break;
+ }
+ }
+ }
+
+ string formattedValue = string.Format(CultureInfo.CurrentCulture, format, date);
+ this.DispatchCommandResult(new PluginResult(PluginResult.Status.OK, this.WrapIntoJSON(formattedValue)));
+ }
+ catch (Exception e)
+ {
+ this.DispatchCommandResult(new PluginResult(PluginResult.Status.ERROR, new GlobalizationError(ErrorCode.FormattingError)));
+ }
+ }
+
+ /// <summary>
+ /// Parses a date formatted as a string according to the client's user preferences and calendar using the time zone of the client and returns the corresponding date object
+ /// </summary>
+ /// <param name="options"></param>
+ public void stringToDate(string options)
+ {
+ GlobalizationOptions globalOptions;
+
+ try
+ {
+ string[] args = JSON.JsonHelper.Deserialize<string[]>(options);
+ globalOptions = JSON.JsonHelper.Deserialize<GlobalizationOptions>(args[0]);
+ }
+ catch (Exception e)
+ {
+ DispatchCommandResult(new PluginResult(PluginResult.Status.JSON_EXCEPTION));
+ return;
+ }
+
+ try
+ {
+ if (string.IsNullOrEmpty(globalOptions.DateString))
+ {
+ DispatchCommandResult(new PluginResult(PluginResult.Status.JSON_EXCEPTION));
+ return;
+ }
+
+ string format = "M/dd/yy H:m:s"; // short datetime by default
+ int formatLength = 0; //default format
+ int selector = 0; //default selector
+
+ if (globalOptions.AdditionalOptions != null)
+ {
+ if (globalOptions.AdditionalOptions.FormatLength != null)
+ {
+ string t = globalOptions.AdditionalOptions.FormatLength;
+
+ if (t.Equals(GlobalizationOptions.Full))
+ {
+ formatLength++;
+ }
+ }
+
+ if (globalOptions.AdditionalOptions.Selector != null)
+ {
+ string t = globalOptions.AdditionalOptions.Selector;
+
+ if (t.Equals(GlobalizationOptions.DateSelector))
+ {
+ selector += 10;
+ }
+ else if (t.Equals(GlobalizationOptions.TimeSelector))
+ {
+ selector += 20;
+ }
+ }
+
+ //determine return value
+ int method = formatLength + selector;
+
+ switch (method)
+ {
+ case 1: // full datetime
+ {
+ format = "MMMM/dddd/yyyy HH:mm:ss tt";
+ break;
+ }
+ case 10: // short date
+ {
+ format = "d";
+ break;
+ }
+ case 11: // full date
+ {
+ format = "D";
+ break;
+ }
+ case 20: // short time
+ {
+ format = "t";
+ break;
+ }
+ case 21: // full time
+ {
+ format = "T";
+ break;
+ }
+ default: // short datetime
+ {
+ format = "M/dd/yy H:m:s";
+ break;
+ }
+ }
+ }
+
+ DateTime date = DateTime.ParseExact(globalOptions.DateString, format, CultureInfo.CurrentCulture);
+ DateFormat dateFormat = new DateFormat(date.Year, date.Month, date.Day, date.Hour, date.Minute, date.Second, date.Millisecond);
+ this.DispatchCommandResult(new PluginResult(PluginResult.Status.OK, dateFormat));
+
+ }
+ catch (Exception e)
+ {
+ this.DispatchCommandResult(new PluginResult(PluginResult.Status.ERROR, new GlobalizationError(ErrorCode.ParsingError)));
+ }
+ }
+
+ /// <summary>
+ /// Gets a pattern string for formatting and parsing dates according to the client's user preferences.
+ /// </summary>
+ /// <param name="options"></param>
+ public void getDatePattern(string options)
+ {
+ GlobalizationOptions globalOptions;
+
+ try
+ {
+ string[] args = JSON.JsonHelper.Deserialize<string[]>(options);
+ globalOptions = JSON.JsonHelper.Deserialize<GlobalizationOptions>(args[0]);
+ }
+ catch (Exception e)
+ {
+ DispatchCommandResult(new PluginResult(PluginResult.Status.JSON_EXCEPTION));
+ return;
+ }
+
+ try
+ {
+ DateTimeFormatInfo dateFormatInfo = DateTimeFormatInfo.CurrentInfo;
+ string pattern = dateFormatInfo.FullDateTimePattern; // full datetime by default
+ int formatLength = 0; //default format
+ int selector = 0; //default selector
+
+ if (globalOptions.AdditionalOptions != null)
+ {
+ if (globalOptions.AdditionalOptions.FormatLength != null)
+ {
+ string t = globalOptions.AdditionalOptions.FormatLength;
+
+ if (t.Equals(GlobalizationOptions.Full))
+ {
+ formatLength++;
+ }
+ }
+
+ if (globalOptions.AdditionalOptions.Selector != null)
+ {
+ string t = globalOptions.AdditionalOptions.Selector;
+
+ if (t.Equals(GlobalizationOptions.DateSelector))
+ {
+ selector += 10;
+ }
+ else if (t.Equals(GlobalizationOptions.TimeSelector))
+ {
+ selector += 20;
+ }
+ }
+
+ //determine return value
+ int method = formatLength + selector;
+
+ switch (method)
+ {
+ case 1: // full datetime
+ {
+ pattern = dateFormatInfo.FullDateTimePattern;
+ break;
+ }
+ case 10: // short date
+ {
+ pattern = dateFormatInfo.ShortDatePattern;
+ break;
+ }
+ case 11: // full date
+ {
+ pattern = dateFormatInfo.LongDatePattern;
+ break;
+ }
+ case 20: // short time
+ {
+ pattern = dateFormatInfo.ShortTimePattern;
+ break;
+ }
+ case 21: // full time
+ {
+ pattern = dateFormatInfo.LongTimePattern;
+ break;
+ }
+ default: // short datetime
+ {
+ // Seems like C# doesn't support short datetime pattern so we use full format
+ // http://msdn.microsoft.com/en-us/library/1at0z4ew%28v=vs.71%29.aspx
+ pattern = dateFormatInfo.FullDateTimePattern;
+ break;
+ }
+ }
+ }
+
+ TimeZoneInfo localZone = TimeZoneInfo.Local;
+ DatePattern datePattern = new DatePattern(pattern, localZone.DisplayName, localZone.BaseUtcOffset.TotalSeconds, 0);
+ this.DispatchCommandResult(new PluginResult(PluginResult.Status.OK, datePattern));
+ }
+ catch (Exception e)
+ {
+ this.DispatchCommandResult(new PluginResult(PluginResult.Status.ERROR, new GlobalizationError(ErrorCode.PatternError)));
+ }
+ }
+
+ /// <summary>
+ /// Gets an array of either the names of the months or days of the week according to the client's user preferences and calendar.
+ /// </summary>
+ /// <param name="options"></param>
+ public void getDateNames(string options)
+ {
+ GlobalizationOptions globalOptions;
+
+ try
+ {
+ string[] args = JSON.JsonHelper.Deserialize<string[]>(options);
+ globalOptions = JSON.JsonHelper.Deserialize<GlobalizationOptions>(args[0]);
+ }
+ catch (Exception e)
+ {
+ DispatchCommandResult(new PluginResult(PluginResult.Status.JSON_EXCEPTION));
+ return;
+ }
+
+ try
+ {
+ int type = 0; //default wide
+ int item = 0; //default months
+
+ if(globalOptions.AdditionalOptions != null)
+ {
+ if(globalOptions.AdditionalOptions.Type != null)
+ {
+ string t = globalOptions.AdditionalOptions.Type;
+
+ if(t.Equals(GlobalizationOptions.Narrow))
+ {
+ type++;
+ }
+ }
+
+ if (globalOptions.AdditionalOptions.Item != null)
+ {
+ string t = globalOptions.AdditionalOptions.Item;
+
+ if (t.Equals(GlobalizationOptions.Days))
+ {
+ item += 10;
+ }
+ }
+ }
+
+ //determine return value
+ int method = item + type;
+ string[] namesArray;
+ CultureInfo currentCulture = CultureInfo.CurrentCulture;
+
+ if (method == 1) //months and narrow
+ {
+ namesArray = currentCulture.DateTimeFormat.AbbreviatedMonthNames;
+ }
+ else if (method == 10) //days and wide
+ {
+ namesArray = currentCulture.DateTimeFormat.DayNames;
+ }
+ else if (method == 11) //days and narrow
+ {
+ namesArray = currentCulture.DateTimeFormat.AbbreviatedDayNames;
+ }
+ else //default: months and wide
+ {
+ namesArray = currentCulture.DateTimeFormat.MonthNames;
+ }
+
+ this.DispatchCommandResult(new PluginResult(PluginResult.Status.OK, this.WrapIntoJSON(namesArray)));
+ }
+ catch (Exception e)
+ {
+ this.DispatchCommandResult(new PluginResult(PluginResult.Status.ERROR, new GlobalizationError()));
+ }
+ }
+
+ /// <summary>
+ /// Gets a number formatted as a string according to the client's user preferences.
+ /// </summary>
+ /// <param name="options"></param>
+ public void numberToString(string options)
+ {
+ GlobalizationOptions globalOptions;
+
+ try
+ {
+ string[] args = JSON.JsonHelper.Deserialize<string[]>(options);
+ globalOptions = JSON.JsonHelper.Deserialize<GlobalizationOptions>(args[0]);
+ }
+ catch (Exception e)
+ {
+ DispatchCommandResult(new PluginResult(PluginResult.Status.JSON_EXCEPTION));
+ return;
+ }
+
+ try
+ {
+ string format = string.Empty;
+ string numberFormatType = (globalOptions.AdditionalOptions == null || string.IsNullOrEmpty(globalOptions.AdditionalOptions.Type)) ?
+ GlobalizationOptions.Decimal : globalOptions.AdditionalOptions.Type;
+
+ switch (numberFormatType)
+ {
+ case GlobalizationOptions.Percent: {
+ format = "{0:p}";
+ break;
+ }
+
+ case GlobalizationOptions.Currency:
+ {
+ format = "{0:c}";
+ break;
+ }
+
+ default: {
+ format = "{0:f}";
+ break;
+ }
+ }
+
+ string formattedValue = string.Format(CultureInfo.CurrentCulture, format, globalOptions.Number);
+ this.DispatchCommandResult(new PluginResult(PluginResult.Status.OK, this.WrapIntoJSON(formattedValue)));
+
+ }
+ catch (Exception e)
+ {
+ this.DispatchCommandResult(new PluginResult(PluginResult.Status.ERROR, new GlobalizationError(ErrorCode.FormattingError)));
+ }
+ }
+
+ /// <summary>
+ /// Gets a number formatted as a string according to the client's user preferences and returns the corresponding number.
+ /// </summary>
+ /// <param name="options"></param>
+ public void stringToNumber(string options)
+ {
+ GlobalizationOptions globalOptions;
+
+ try
+ {
+ string[] args = JSON.JsonHelper.Deserialize<string[]>(options);
+ globalOptions = JSON.JsonHelper.Deserialize<GlobalizationOptions>(args[0]);
+ }
+ catch (Exception e)
+ {
+ DispatchCommandResult(new PluginResult(PluginResult.Status.JSON_EXCEPTION));
+ return;
+ }
+
+ try
+ {
+ if (string.IsNullOrEmpty(globalOptions.NumberString))
+ {
+ DispatchCommandResult(new PluginResult(PluginResult.Status.JSON_EXCEPTION));
+ return;
+ }
+
+ string numberString = globalOptions.NumberString;
+ string numberFormatType = (globalOptions.AdditionalOptions == null || string.IsNullOrEmpty(globalOptions.AdditionalOptions.Type)) ?
+ GlobalizationOptions.Decimal : globalOptions.AdditionalOptions.Type;
+
+ NumberStyles numberStyle;
+
+ switch (numberFormatType)
+ {
+ case GlobalizationOptions.Percent:
+ {
+ numberStyle = NumberStyles.Any;
+ numberString = numberString.Replace(System.Globalization.CultureInfo.CurrentCulture.NumberFormat.PercentSymbol, "");
+ break;
+ }
+
+ case GlobalizationOptions.Currency:
+ {
+ numberStyle = NumberStyles.Currency;
+ break;
+ }
+
+ default:
+ {
+ numberStyle = NumberStyles.Number;
+ break;
+ }
+ }
+
+ double value = double.Parse(numberString, numberStyle, CultureInfo.CurrentCulture);
+ this.DispatchCommandResult(new PluginResult(PluginResult.Status.OK, this.WrapIntoJSON(value)));
+
+ }
+ catch (Exception e)
+ {
+ this.DispatchCommandResult(new PluginResult(PluginResult.Status.ERROR, new GlobalizationError(ErrorCode.ParsingError)));
+ }
+ }
+
+
+ /// <summary>
+ /// Gets a pattern string for formatting and parsing numbers according to the client's user preferences.
+ /// </summary>
+ /// <param name="options"></param>
+ public void getNumberPattern(string options)
+ {
+ GlobalizationOptions globalOptions;
+
+ try
+ {
+ string[] args = JSON.JsonHelper.Deserialize<string[]>(options);
+ globalOptions = JSON.JsonHelper.Deserialize<GlobalizationOptions>(args[0]);
+ }
+ catch (Exception e)
+ {
+ DispatchCommandResult(new PluginResult(PluginResult.Status.JSON_EXCEPTION));
+ return;
+ }
+
+ try
+ {
+ CultureInfo cultureInfo = CultureInfo.CurrentCulture;
+ NumberFormatInfo formatInfo = cultureInfo.NumberFormat;
+ string numberFormatType = (globalOptions.AdditionalOptions == null || string.IsNullOrEmpty(globalOptions.AdditionalOptions.Type)) ?
+ GlobalizationOptions.Decimal : globalOptions.AdditionalOptions.Type;
+ NumberPattern pattern = null;
+ string symbol;
+
+ // TODO find out how to get format pattern and the number of fraction digits
+ switch (numberFormatType)
+ {
+ case GlobalizationOptions.Percent:
+ {
+ symbol = formatInfo.PercentSymbol;
+ pattern = new NumberPattern("", symbol, 0, formatInfo.PercentPositivePattern.ToString(), formatInfo.PercentNegativePattern.ToString(), 0, formatInfo.PercentDecimalSeparator, formatInfo.PercentGroupSeparator);
+ break;
+ }
+ case GlobalizationOptions.Currency:
+ {
+ symbol = formatInfo.CurrencySymbol;
+ pattern = new NumberPattern("", symbol, 0, formatInfo.CurrencyPositivePattern.ToString(), formatInfo.CurrencyNegativePattern.ToString(), 0, formatInfo.CurrencyDecimalSeparator, formatInfo.CurrencyGroupSeparator);
+ break;
+ }
+ default:
+ {
+ symbol = formatInfo.NumberDecimalSeparator;
+ pattern = new NumberPattern("", symbol, 0, "", formatInfo.NumberNegativePattern.ToString(), 0, formatInfo.NumberDecimalSeparator, formatInfo.NumberGroupSeparator);
+ break;
+ }
+ }
+
+ this.DispatchCommandResult(new PluginResult(PluginResult.Status.OK, pattern));
+ }
+ catch (Exception e)
+ {
+ this.DispatchCommandResult(new PluginResult(PluginResult.Status.ERROR, new GlobalizationError(ErrorCode.PatternError)));
+ }
+ }
+
+ /// <summary>
+ /// Gets a pattern string for formatting and parsing currency values according to the client's user preferences and ISO 4217 currency code.
+ /// </summary>
+ /// <param name="options"></param>
+ public void getCurrencyPattern(string options)
+ {
+ GlobalizationOptions globalOptions;
+
+ try
+ {
+ string[] args = JSON.JsonHelper.Deserialize<string[]>(options);
+ globalOptions = JSON.JsonHelper.Deserialize<GlobalizationOptions>(args[0]);
+ }
+ catch (Exception e)
+ {
+ DispatchCommandResult(new PluginResult(PluginResult.Status.JSON_EXCEPTION));
+ return;
+ }
+
+ try
+ {
+ if (string.IsNullOrEmpty(globalOptions.CurrencyCode))
+ {
+ DispatchCommandResult(new PluginResult(PluginResult.Status.JSON_EXCEPTION));
+ return;
+ }
+
+ string currencyCode = globalOptions.CurrencyCode;
+
+ // temporary not supported via lack of api required
+ this.DispatchCommandResult(new PluginResult(PluginResult.Status.INVALID_ACTION, "Not supported"));
+ return;
+
+ // TODO find the way to get currency info from currency code
+ // http://stackoverflow.com/questions/12373800/3-digit-currency-code-to-currency-symbol
+ // http://stackoverflow.com/questions/6924067/how-to-get-specific-culture-currency-pattern
+ // CultureInfo cultureInfo = new CultureInfo(currencyCode);
+ // NumberFormatInfo numberFormat = cultureInfo.NumberFormat;
+ }
+ catch (Exception e)
+ {
+ this.DispatchCommandResult(new PluginResult(PluginResult.Status.ERROR, new GlobalizationError(ErrorCode.FormattingError)));
+ }
+ }
+
+ #endregion
+
+
+ #region private methods
+
+ /// <summary>
+ /// Wraps data into JSON format
+ /// </summary>
+ /// <param name="data">data</param>
+ /// <returns>data formatted as JSON object</returns>
+ private string WrapIntoJSON<T>(T data, string keyName = "value")
+ {
+ string param = "{0}";
+ string stringifiedData = data.ToString();
+
+ if(data.GetType() == typeof(string))
+ {
+ param = "\""+ param +"\"";
+ }
+
+ if (data.GetType() == typeof(bool))
+ {
+ stringifiedData = stringifiedData.ToLower();
+ }
+
+ if(data.GetType() == typeof (string[]))
+ {
+ stringifiedData = JSON.JsonHelper.Serialize(data);
+ }
+
+ var formattedData = string.Format("\""+ keyName + "\":" + param, stringifiedData);
+ formattedData = "{" + formattedData + "}";
+
+ return formattedData;
+ }
+
+ #endregion
+ }
+}
http://git-wip-us.apache.org/repos/asf/cordova-wp8/blob/880e2f3b/plugins/www/plugins/Globalization/global.html
----------------------------------------------------------------------
diff --git a/plugins/www/plugins/Globalization/global.html b/plugins/www/plugins/Globalization/global.html
new file mode 100644
index 0000000..e7f3af6
--- /dev/null
+++ b/plugins/www/plugins/Globalization/global.html
@@ -0,0 +1,143 @@
+<!DOCTYPE HTML>
+<html>
+ <head>
+ <meta name="viewport" content="width=device-width, height=device-height, initial-scale=1.0, maximum-scale=1.0, user-scalable=no;" />
+ <meta http-equiv="Content-type" content="text/html; charset=utf-8"/>
+
+ <title>Globalization Example</title>
+
+ <link rel="stylesheet" href="../../master.css" type="text/css" media="screen"/>
+
+ <script type="text/javascript">
+ // provide our own console if it does not exist, huge dev aid!
+ if (typeof window.console == "undefined") {
+ window.console = { log: function (str) { window.external.Notify(str); } };
+ }
+
+ // output any errors to console log, created above.
+ window.onerror = function (e) {
+ console.log("window.onerror ::" + JSON.stringify(e));
+ };
+
+ console.log("Installed console ! ");
+ </script>
+
+ <script type="text/javascript" charset="utf-8" src="../../cordova-2.2.0.js"></script>
+
+ <script type="text/javascript" charset="utf-8" src="globalization.js"></script>
+
+ <script type="text/javascript" charset="utf-8">
+
+ // Wait for PhoneGap to load
+ //
+ function onLoad() {
+ document.addEventListener("deviceready", onDeviceReady, false);
+ }
+
+ // PhoneGap is ready
+ //
+ function onDeviceReady() {
+
+ console.log("onDeviceReady fired");
+
+ }
+ function getLocale() {
+ window.plugins.globalization.getLocaleName(
+ function (locale) {
+ alert('locale: ' + locale.value);
+ },
+ function () {console.log("error getting locale");}
+ );
+ }
+ function getLanguage() {
+ window.plugins.globalization.getPreferredLanguage(
+ function (language) {
+ alert('language: ' + language.value);
+ },
+ function () {console.log("error getting language");}
+ );
+ }
+ function getDate() {
+ window.plugins.globalization.dateToString(new Date(),
+ function (date) {alert('date: ' + date.value + '\n');},
+ function (errorCode) {alert(errorCode);},
+ {formatLength:'full', selector:'date'});
+ }
+ function stringToDate() {
+ var date = new Date();
+ var stringDate = date.getMonth() + '/' + date.getDay() + '/' + date.getFullYear();
+ window.plugins.globalization.stringToDate(stringDate,
+ function (date) {alert('year:' + date.year + ', month: ' + date.month + ', day: ' + date.day + '\n');},
+ function (errorCode) {alert(errorCode);},
+ {formatLength:'short',selector: 'date'});
+ }
+ function getDatePattern() {
+ window.plugins.globalization.getDatePattern(
+ function (date) { alert('short date pattern: "' + date.pattern + '", UTC offset: ' + date.utc_offset + 'sec.' +'\n'); },
+ function () {console.log("error getting date pattern");},
+ {formatLength:'short', selector: 'date'});
+ }
+ function getDateNames() {
+ window.plugins.globalization.getDateNames(
+ function (date) { alert('Date names: ' + JSON.stringify(date.value) + '\n'); },
+ function () {console.log("error getting date names");},
+ {type: 'wide', item: 'days'});
+ }
+ function isDayLightSavings() {
+ window.plugins.globalization.isDayLightSavingsTime(new Date(),
+ function (date) {alert('isDayLightSavingsTime: ' + date.dst + '\n');},
+ function () { console.log("error getting daylight savings value"); });
+
+ }
+ function getNumberPattern() {
+ window.plugins.globalization.getNumberPattern(
+ function (pattern) {alert('Pattern:' + pattern.pattern + '\n');},
+ function () {console.log("error getting number pattern");});
+ }
+
+ function firstDayOfWeek() {
+ window.plugins.globalization.getFirstDayOfWeek(
+ function (obj) { alert('First day of week: ' + obj.value + '\n'); },
+ function () { console.log("error getting first day of week"); });
+ }
+
+ function numToStr() {
+ window.plugins.globalization.numberToString(123.45,
+ function (obj) { alert('number to string: ' + obj.value + '\n'); },
+ function () { console.log("error getting number to string"); },{type : 'currency'});
+ }
+
+ function strToNum() {
+ window.plugins.globalization.stringToNumber('123.45%',
+ function (obj) { alert('string to number: ' + obj.value + '\n'); },
+ function () { console.log("error getting string to number"); },{type : 'percent'});
+ }
+
+ function getCurrencyPattern() {
+ window.plugins.globalization.getCurrencyPattern("RUB",
+ function (obj) { alert('number to string: ' + obj.value + '\n'); },
+ function () { console.log("error getting number to string"); });
+ }
+
+ </script>
+ </head>
+ <body>
+ <h1>Globalization</h1>
+ <div><button onclick="getLocale();">Get Locale</button></div>
+ <div><button onclick="getLanguage();">Get preferred language</button></div>
+ <div><button onclick="isDayLightSavings();">Is Daylight savings?</button></div>
+ <div><button onclick="firstDayOfWeek();">first day of week</button></div>
+ <div><button onclick="getDate();">Date to string</button></div>
+ <div><button onclick="stringToDate();">String to date</button></div>
+ <div><button onclick="getDateNames();">Get date names</button></div>
+ <div><button onclick="getDatePattern();">Get Date Pattern</button></div>
+ <!--<div><button onclick="numToStr();">Get number to string</button></div>-->
+ <!--<div><button onclick="strToNum();">Get string to number</button></div>-->
+ <!--<div><button onclick="getNumberPattern();">Get Number Pattern</button></div>-->
+ <div>
+ <span id="locale"></span>
+ </div>
+
+ </body>
+</html>
+
http://git-wip-us.apache.org/repos/asf/cordova-wp8/blob/880e2f3b/plugins/www/plugins/Globalization/globalization.js
----------------------------------------------------------------------
diff --git a/plugins/www/plugins/Globalization/globalization.js b/plugins/www/plugins/Globalization/globalization.js
new file mode 100644
index 0000000..e593633
--- /dev/null
+++ b/plugins/www/plugins/Globalization/globalization.js
@@ -0,0 +1,540 @@
+var Globalization = function() {
+};
+
+Globalization.prototype.getPreferredLanguage = function(successCB, failureCB)
+{
+ // successCallback required
+ if (typeof successCB != "function") {
+ console.log("Globalization.getPreferredLanguage Error: successCB is not a function");
+ return;
+ }
+
+ // errorCallback required
+ if (typeof failureCB != "function") {
+ console.log("Globalization.getPreferredLanguage Error: failureCB is not a function");
+ return;
+ }
+
+ cordova.exec(successCB, failureCB, "Globalization","getPreferredLanguage", []);
+};
+
+/**
+* Returns the string identifier for the client's current locale setting.
+* It returns the locale identifier string to the successCB callback with a
+* properties object as a parameter. If there is an error getting the locale,
+* then the errorCB callback is invoked.
+*
+* @param {Function} successCB
+* @param {Function} errorCB
+*
+* @return Object.value {String}: The locale identifier
+*
+* @error GlobalizationError.UNKNOWN_ERROR
+*
+* Example
+* globalization.getLocaleName(function (locale) {alert('locale:' + locale.value + '\n');},
+* function () {});
+*/
+Globalization.prototype.getLocaleName = function(successCB, failureCB)
+{
+ // successCallback required
+ if (typeof successCB != "function") {
+ console.log("Globalization.getLocaleName Error: successCB is not a function");
+ return;
+ }
+
+ // errorCallback required
+ if (typeof failureCB != "function") {
+ console.log("Globalization.getLocaleName Error: failureCB is not a function");
+ return;
+ }
+ cordova.exec(successCB, failureCB, "Globalization","getLocaleName", []);
+};
+
+
+/**
+* Returns a date formatted as a string according to the client's user preferences and
+* calendar using the time zone of the client. It returns the formatted date string to the
+* successCB callback with a properties object as a parameter. If there is an error
+* formatting the date, then the errorCB callback is invoked.
+*
+* The defaults are: formatLenght="short" and selector="date and time"
+*
+* @param {Date} date
+* @param {Function} successCB
+* @param {Function} errorCB
+* @param {Object} options {optional}
+* formatLength {String}: 'short', 'medium', 'long', or 'full'
+* selector {String}: 'date', 'time', or 'date and time'
+*
+* @return Object.value {String}: The localized date string
+*
+* @error GlobalizationError.FORMATTING_ERROR
+*
+* Example
+* globalization.dateToString(new Date(),
+* function (date) {alert('date:' + date.value + '\n');},
+* function (errorCode) {alert(errorCode);},
+* {formatLength:'short'});
+*/
+Globalization.prototype.dateToString = function(date, successCB, failureCB, options)
+{
+ // successCallback required
+ if (typeof successCB != "function") {
+ console.log("Globalization.dateToString Error: successCB is not a function");
+ return;
+ }
+
+ // errorCallback required
+ if (typeof failureCB != "function") {
+ console.log("Globalization.dateToString Error: failureCB is not a function");
+ return;
+ }
+
+
+ if (date instanceof Date){
+ var dateValue;
+ dateValue = date.valueOf();
+ cordova.exec(successCB, failureCB, "Globalization", "dateToString", [{"date": dateValue, "options": options}]);
+ }
+ else {
+ console.log("Globalization.dateToString Error: date is not a Date object");
+ }
+};
+
+
+/**
+* Parses a date formatted as a string according to the client's user
+* preferences and calendar using the time zone of the client and returns
+* the corresponding date object. It returns the date to the successCB
+* callback with a properties object as a parameter. If there is an error
+* parsing the date string, then the errorCB callback is invoked.
+*
+* The defaults are: formatLength="short" and selector="date and time"
+*
+* @param {String} dateString
+* @param {Function} successCB
+* @param {Function} errorCB
+* @param {Object} options {optional}
+* formatLength {String}: 'short', 'medium', 'long', or 'full'
+* selector {String}: 'date', 'time', or 'date and time'
+*
+* @return Object.year {Number}: The four digit year
+* Object.month {Number}: The month from (0 - 11)
+* Object.day {Number}: The day from (1 - 31)
+* Object.hour {Number}: The hour from (0 - 23)
+* Object.minute {Number}: The minute from (0 - 59)
+* Object.second {Number}: The second from (0 - 59)
+* Object.millisecond {Number}: The milliseconds (from 0 - 999),
+* not available on all platforms
+*
+* @error GlobalizationError.PARSING_ERROR
+*
+* Example
+* globalization.stringToDate('4/11/2011',
+* function (date) { alert('Month:' + date.month + '\n' +
+* 'Day:' + date.day + '\n' +
+* 'Year:' + date.year + '\n');},
+* function (errorCode) {alert(errorCode);},
+* {selector:'date'});
+*/
+Globalization.prototype.stringToDate = function(dateString, successCB, failureCB, options)
+{
+ // successCallback required
+ if (typeof successCB != "function") {
+ console.log("Globalization.stringToDate Error: successCB is not a function");
+ return;
+ }
+
+ // errorCallback required
+ if (typeof failureCB != "function") {
+ console.log("Globalization.stringToDate Error: failureCB is not a function");
+ return;
+ }
+ if (typeof dateString == "string"){
+ cordova.exec(successCB, failureCB, "Globalization", "stringToDate", [{"dateString": dateString, "options": options}]);
+ }
+ else {
+ console.log("Globalization.stringToDate Error: dateString is not a string");
+ }
+};
+
+
+/**
+* Returns a pattern string for formatting and parsing dates according to the client's
+* user preferences. It returns the pattern to the successCB callback with a
+* properties object as a parameter. If there is an error obtaining the pattern,
+* then the errorCB callback is invoked.
+*
+* The defaults are: formatLength="short" and selector="date and time"
+*
+* @param {Function} successCB
+* @param {Function} errorCB
+* @param {Object} options {optional}
+* formatLength {String}: 'short', 'medium', 'long', or 'full'
+* selector {String}: 'date', 'time', or 'date and time'
+*
+* @return Object.pattern {String}: The date and time pattern for formatting and parsing dates.
+* The patterns follow Unicode Technical Standard #35
+* http://unicode.org/reports/tr35/tr35-4.html
+* Object.timezone {String}: The abbreviated name of the time zone on the client
+* Object.utc_offset {Number}: The current difference in seconds between the client's
+* time zone and coordinated universal time.
+* Object.dst_offset {Number}: The current daylight saving time offset in seconds
+* between the client's non-daylight saving's time zone
+* and the client's daylight saving's time zone.
+*
+* @error GlobalizationError.PATTERN_ERROR
+*
+* Example
+* globalization.getDatePattern(
+* function (date) {alert('pattern:' + date.pattern + '\n');},
+* function () {},
+* {formatLength:'short'});
+*/
+Globalization.prototype.getDatePattern = function(successCB, failureCB, options)
+{
+ // successCallback required
+ if (typeof successCB != "function") {
+ console.log("Globalization.getDatePattern Error: successCB is not a function");
+ return;
+ }
+
+ // errorCallback required
+ if (typeof failureCB != "function") {
+ console.log("Globalization.getDatePattern Error: failureCB is not a function");
+ return;
+ }
+
+ cordova.exec(successCB, failureCB, "Globalization", "getDatePattern", [{"options": options}]);
+};
+
+
+/**
+* Returns an array of either the names of the months or days of the week
+* according to the client's user preferences and calendar. It returns the array of names to the
+* successCB callback with a properties object as a parameter. If there is an error obtaining the
+* names, then the errorCB callback is invoked.
+*
+* The defaults are: type="wide" and item="months"
+*
+* @param {Function} successCB
+* @param {Function} errorCB
+* @param {Object} options {optional}
+* type {String}: 'narrow' or 'wide'
+* item {String}: 'months', or 'days'
+*
+* @return Object.value {Array{String}}: The array of names starting from either
+* the first month in the year or the
+* first day of the week.
+* @error GlobalizationError.UNKNOWN_ERROR
+*
+* Example
+* globalization.getDateNames(function (names) {
+* for(var i = 0; i < names.value.length; i++) {
+* alert('Month:' + names.value[i] + '\n');}},
+* function () {});
+*/
+Globalization.prototype.getDateNames = function(successCB, failureCB, options)
+{
+ // successCallback required
+ if (typeof successCB != "function") {
+ console.log("Globalization.getDateNames Error: successCB is not a function");
+ return;
+ }
+
+ // errorCallback required
+ if (typeof failureCB != "function") {
+ console.log("Globalization.getDateNames Error: failureCB is not a function");
+ return;
+ }
+ cordova.exec(successCB, failureCB, "Globalization", "getDateNames", [{"options": options}]);
+};
+
+/**
+* Returns whether daylight savings time is in effect for a given date using the client's
+* time zone and calendar. It returns whether or not daylight savings time is in effect
+* to the successCB callback with a properties object as a parameter. If there is an error
+* reading the date, then the errorCB callback is invoked.
+*
+* @param {Date} date
+* @param {Function} successCB
+* @param {Function} errorCB
+*
+* @return Object.dst {Boolean}: The value "true" indicates that daylight savings time is
+* in effect for the given date and "false" indicate that it is not.
+*
+* @error GlobalizationError.UNKNOWN_ERROR
+*
+* Example
+* globalization.isDayLightSavingsTime(new Date(),
+* function (date) {alert('dst:' + date.dst + '\n');}
+* function () {});
+*/
+Globalization.prototype.isDayLightSavingsTime = function(date, successCB, failureCB)
+{
+ // successCallback required
+ if (typeof successCB != "function") {
+ console.log("Globalization.isDayLightSavingsTime Error: successCB is not a function");
+ return;
+ }
+
+ // errorCallback required
+ if (typeof failureCB != "function") {
+ console.log("Globalization.isDayLightSavingsTime Error: failureCB is not a function");
+ return;
+ }
+
+
+ if (date instanceof Date){
+ var dateValue;
+ dateValue = date.valueOf();
+ cordova.exec(successCB, failureCB, "Globalization", "isDayLightSavingsTime", [{"date": dateValue}]);
+ }
+ else {
+ console.log("Globalization.isDayLightSavingsTime Error: date is not a Date object");
+ }
+
+};
+
+/**
+* Returns the first day of the week according to the client's user preferences and calendar.
+* The days of the week are numbered starting from 1 where 1 is considered to be Sunday.
+* It returns the day to the successCB callback with a properties object as a parameter.
+* If there is an error obtaining the pattern, then the errorCB callback is invoked.
+*
+* @param {Function} successCB
+* @param {Function} errorCB
+*
+* @return Object.value {Number}: The number of the first day of the week.
+*
+* @error GlobalizationError.UNKNOWN_ERROR
+*
+* Example
+* globalization.getFirstDayOfWeek(function (day)
+* { alert('Day:' + day.value + '\n');},
+* function () {});
+*/
+Globalization.prototype.getFirstDayOfWeek = function(successCB, failureCB)
+{
+ // successCallback required
+ if (typeof successCB != "function") {
+ console.log("Globalization.getFirstDayOfWeek Error: successCB is not a function");
+ return;
+ }
+
+ // errorCallback required
+ if (typeof failureCB != "function") {
+ console.log("Globalization.getFirstDayOfWeek Error: failureCB is not a function");
+ return;
+ }
+
+ cordova.exec(successCB, failureCB, "Globalization", "getFirstDayOfWeek", []);
+};
+
+
+/**
+* Returns a number formatted as a string according to the client's user preferences.
+* It returns the formatted number string to the successCB callback with a properties object as a
+* parameter. If there is an error formatting the number, then the errorCB callback is invoked.
+*
+* The defaults are: type="decimal"
+*
+* @param {Number} number
+* @param {Function} successCB
+* @param {Function} errorCB
+* @param {Object} options {optional}
+* type {String}: 'decimal', "percent", or 'currency'
+*
+* @return Object.value {String}: The formatted number string.
+*
+* @error GlobalizationError.FORMATTING_ERROR
+*
+* Example
+* globalization.numberToString(3.25,
+* function (number) {alert('number:' + number.value + '\n');},
+* function () {},
+* {type:'decimal'});
+*/
+Globalization.prototype.numberToString = function(number, successCB, failureCB, options)
+{
+ // successCallback required
+ if (typeof successCB != "function") {
+ console.log("Globalization.numberToString Error: successCB is not a function");
+ return;
+ }
+
+ // errorCallback required
+ if (typeof failureCB != "function") {
+ console.log("Globalization.numberToString Error: failureCB is not a function");
+ return;
+ }
+
+ if(typeof number == "number") {
+ cordova.exec(successCB, failureCB, "Globalization", "numberToString", [{"number": number, "options": options}]);
+ }
+ else {
+ console.log("Globalization.numberToString Error: number is not a number");
+ }
+};
+
+/**
+* Parses a number formatted as a string according to the client's user preferences and
+* returns the corresponding number. It returns the number to the successCB callback with a
+* properties object as a parameter. If there is an error parsing the number string, then
+* the errorCB callback is invoked.
+*
+* The defaults are: type="decimal"
+*
+* @param {String} numberString
+* @param {Function} successCB
+* @param {Function} errorCB
+* @param {Object} options {optional}
+* type {String}: 'decimal', "percent", or 'currency'
+*
+* @return Object.value {Number}: The parsed number.
+*
+* @error GlobalizationError.PARSING_ERROR
+*
+* Example
+* globalization.stringToNumber('1234.56',
+* function (number) {alert('Number:' + number.value + '\n');},
+* function () { alert('Error parsing number');});
+*/
+Globalization.prototype.stringToNumber = function(numberString, successCB, failureCB, options)
+{
+ // successCallback required
+ if (typeof successCB != "function") {
+ console.log("Globalization.stringToNumber Error: successCB is not a function");
+ return;
+ }
+
+ // errorCallback required
+ if (typeof failureCB != "function") {
+ console.log("Globalization.stringToNumber Error: failureCB is not a function");
+ return;
+ }
+
+ if(typeof numberString == "string") {
+ cordova.exec(successCB, failureCB, "Globalization", "stringToNumber", [{"numberString": numberString, "options": options}]);
+ }
+ else {
+ console.log("Globalization.stringToNumber Error: numberString is not a string");
+ }
+};
+
+/**
+* Returns a pattern string for formatting and parsing numbers according to the client's user
+* preferences. It returns the pattern to the successCB callback with a properties object as a
+* parameter. If there is an error obtaining the pattern, then the errorCB callback is invoked.
+*
+* The defaults are: type="decimal"
+*
+* @param {Function} successCB
+* @param {Function} errorCB
+* @param {Object} options {optional}
+* type {String}: 'decimal', "percent", or 'currency'
+*
+* @return Object.pattern {String}: The number pattern for formatting and parsing numbers.
+* The patterns follow Unicode Technical Standard #35.
+* http://unicode.org/reports/tr35/tr35-4.html
+* Object.symbol {String}: The symbol to be used when formatting and parsing
+* e.g., percent or currency symbol.
+* Object.fraction {Number}: The number of fractional digits to use when parsing and
+* formatting numbers.
+* Object.rounding {Number}: The rounding increment to use when parsing and formatting.
+* Object.positive {String}: The symbol to use for positive numbers when parsing and formatting.
+* Object.negative: {String}: The symbol to use for negative numbers when parsing and formatting.
+* Object.decimal: {String}: The decimal symbol to use for parsing and formatting.
+* Object.grouping: {String}: The grouping symbol to use for parsing and formatting.
+*
+* @error GlobalizationError.PATTERN_ERROR
+*
+* Example
+* globalization.getNumberPattern(
+* function (pattern) {alert('Pattern:' + pattern.pattern + '\n');},
+* function () {});
+*/
+Globalization.prototype.getNumberPattern = function(successCB, failureCB, options)
+{
+ // successCallback required
+ if (typeof successCB != "function") {
+ console.log("Globalization.getNumberPattern Error: successCB is not a function");
+ return;
+ }
+
+ // errorCallback required
+ if (typeof failureCB != "function") {
+ console.log("Globalization.getNumberPattern Error: failureCB is not a function");
+ return;
+ }
+
+ cordova.exec(successCB, failureCB, "Globalization", "getNumberPattern", [{"options": options}]);
+};
+
+/**
+* Returns a pattern string for formatting and parsing currency values according to the client's
+* user preferences and ISO 4217 currency code. It returns the pattern to the successCB callback with a
+* properties object as a parameter. If there is an error obtaining the pattern, then the errorCB
+* callback is invoked.
+*
+* @param {String} currencyCode
+* @param {Function} successCB
+* @param {Function} errorCB
+*
+* @return Object.pattern {String}: The currency pattern for formatting and parsing currency values.
+* The patterns follow Unicode Technical Standard #35
+* http://unicode.org/reports/tr35/tr35-4.html
+* Object.code {String}: The ISO 4217 currency code for the pattern.
+* Object.fraction {Number}: The number of fractional digits to use when parsing and
+* formatting currency.
+* Object.rounding {Number}: The rounding increment to use when parsing and formatting.
+* Object.decimal: {String}: The decimal symbol to use for parsing and formatting.
+* Object.grouping: {String}: The grouping symbol to use for parsing and formatting.
+*
+* @error GlobalizationError.FORMATTING_ERROR
+*
+* Example
+* globalization.getCurrencyPattern('EUR',
+* function (currency) {alert('Pattern:' + currency.pattern + '\n');}
+* function () {});
+*/
+Globalization.prototype.getCurrencyPattern = function(currencyCode, successCB, failureCB)
+{
+ // successCallback required
+ if (typeof successCB != "function") {
+ console.log("Globalization.getCurrencyPattern Error: successCB is not a function");
+ return;
+ }
+
+ // errorCallback required
+ if (typeof failureCB != "function") {
+ console.log("Globalization.getCurrencyPattern Error: failureCB is not a function");
+ return;
+ }
+
+ if(typeof currencyCode == "string") {
+ cordova.exec(successCB, failureCB, "Globalization", "getCurrencyPattern", [{"currencyCode": currencyCode}]);
+ }
+ else {
+ console.log("Globalization.getCurrencyPattern Error: currencyCode is not a currency code");
+ }
+};
+
+GlobalizationError = function() {
+ this.code = null;
+}
+
+// Globalization error codes
+GlobalizationError.UNKNOWN_ERROR = 0;
+GlobalizationError.FORMATTING_ERROR = 1;
+GlobalizationError.PARSING_ERROR = 2;
+GlobalizationError.PATTERN_ERROR = 3;
+
+
+if(!window.plugins) {
+ window.plugins = {};
+}
+if (!window.plugins.globalization) {
+ window.plugins.globalization = new Globalization();
+}
http://git-wip-us.apache.org/repos/asf/cordova-wp8/blob/880e2f3b/plugins/www/plugins/index.html
----------------------------------------------------------------------
diff --git a/plugins/www/plugins/index.html b/plugins/www/plugins/index.html
index f64c23b..aaa7099 100644
--- a/plugins/www/plugins/index.html
+++ b/plugins/www/plugins/index.html
@@ -49,6 +49,7 @@
<a href="LiveTiles/liveTilesExample.html" class="btn large">Live tile</a>
<a href="PGMapLauncher/map.html" class="btn large">Map launcher</a>
<a href="PGSocialShare/share.html" class="btn large">Social share</a>
+ <a href="Globalization/global.html" class="btn large">Globalization</a>
</div>
</body>
</html>