MBS Xojo Developer Conference and Training
Join us from 3rd to 6th May 2017 in Berlin, Germany.

Platforms to show: All Mac Windows Linux Cross-Platform

CDblMBS(text as string, byref value as Double, locale as string = "") as boolean
global method, Currency, Date and Time Format, MBS Util Plugin (Locale),
Plugin version: 13.0, Mac: Yes, Win: Yes, Linux: Yes, Console & Web: Yes, Feedback.

Function: Parses a double value from a text with given locale.
Example:
dim value as Double
if CDblMBS("12,345", value, "de_DE") then
MsgBox str(value)
end if
Notes:
Returns true on success and false on failure.
Value is set to the value detected.
Raises exception on invalid locale.

Some examples using this method:

FormatDateMBS(format as string, value as date, locale as string = "") as string
global method, Currency, Date and Time Format, MBS Util Plugin (Locale),
Plugin version: 13.2, Mac: Yes, Win: Yes, Linux: Yes, Console & Web: Yes, Feedback.

Function: Formats a date with C time formatting functions.
Example:
// for Mac, Windows and Linux we usually have different locale names
dim fr as string
#if TargetMacOS then
fr = "fr_FR"
#elseif TargetWin32 then
fr = "fra"
#elseif TargetLinux
fr = "fr_FR.UTF8"
#else
?
#endif

dim d as new date
MsgBox FormatDateMBS("%x %X", d, fr)
Notes:
locale is the name of the locale to use. You can pass empty string to use default/current locale.
Format is a format string like for strftime command in C.

The format specification is a string and may contain special character sequences called conversion specifications, each of which is introduced by a '%' character and terminated by some other character known as a conversion specifier character. All other character sequences are ordinary character sequences.

The characters of ordinary character sequences (including the null byte) are copied verbatim from format to s. However, the characters of conversion specifications are replaced as follows:

%aThe abbreviated weekday name according to the current locale.
%AThe full weekday name according to the current locale.
%bThe abbreviated month name according to the current locale.
%BThe full month name according to the current locale.
%cThe preferred date and time representation for the current locale.
%CThe century number (year/100) as a 2-digit integer. (SU)
%dThe day of the month as a decimal number (range 01 to 31).
%DEquivalent to %m/%d/%y. (Yecch-for Americans only. Americans should note that in other countries %d/%m/%y is rather common. This means that in international context this format is ambiguous and should not be used.) (SU)
%eLike %d, the day of the month as a decimal number, but a leading zero is replaced by a space. (SU)
%EModifier: use alternative format, see below. (SU)
%FEquivalent to %Y-%m-%d (the ISO 8601 date format). (C99)
%GThe ISO 8601 week-based year (see NOTES) with century as a decimal number. The 4-digit year corresponding to the ISO week number (see %V). This has the same format and value as %Y, except that if the ISO week number belongs to the previous or next year, that year is used instead. (TZ)
%gLike %G, but without century, that is, with a 2-digit year (00-99). (TZ)
%hEquivalent to %b. (SU)
%HThe hour as a decimal number using a 24-hour clock (range 00 to 23).
%IThe hour as a decimal number using a 12-hour clock (range 01 to 12).
%jThe day of the year as a decimal number (range 001 to 366).
%kThe hour (24-hour clock) as a decimal number (range 0 to 23); single digits are preceded by a blank. (See also %H.) (TZ)
%lThe hour (12-hour clock) as a decimal number (range 1 to 12); single digits are preceded by a blank. (See also %I.) (TZ)
%mThe month as a decimal number (range 01 to 12).
%MThe minute as a decimal number (range 00 to 59).
%nA newline character. (SU)
%OModifier: use alternative format, see below. (SU)
%pEither "AM" or "PM" according to the given time value, or the corresponding strings for the current locale. Noon is treated as "PM" and midnight as "AM".
%PLike %p but in lowercase: "am" or "pm" or a corresponding string for the current locale. (GNU)
%rThe time in a.m. or p.m. notation. In the POSIX locale this is equivalent to %I:%M:%S %p. (SU)
%RThe time in 24-hour notation (%H:%M). (SU) For a version including the seconds, see %T below.
%sThe number of seconds since the Epoch, 1970-01-01 00:00:00 +0000 (UTC). (TZ)
%SThe second as a decimal number (range 00 to 60). (The range is up to 60 to allow for occasional leap seconds.)
%tA tab character. (SU)
%TThe time in 24-hour notation (%H:%M:%S). (SU)
%uThe day of the week as a decimal, range 1 to 7, Monday being 1. See also %w. (SU)
%UThe week number of the current year as a decimal number, range 00 to 53, starting with the first Sunday as the first day of week 01. See also %V and %W.
%VThe ISO 8601 week number (see NOTES) of the current year as a decimal number, range 01 to 53, where week 1 is the first week that has at least 4 days in the new year. See also %U and %W. (SU)
%wThe day of the week as a decimal, range 0 to 6, Sunday being 0. See also %u.
%WThe week number of the current year as a decimal number, range 00 to 53, starting with the first Monday as the first day of week 01.
%xThe preferred date representation for the current locale without the time.
%XThe preferred time representation for the current locale without the date.
%yThe year as a decimal number without a century (range 00 to 99).
%YThe year as a decimal number including the century.
%zThe +hhmm or -hhmm numeric timezone (that is, the hour and minute offset from UTC). (SU)
%ZThe timezone or name or abbreviation.
%+The date and time in date(1) format. (TZ) (Not supported in glibc2.)
%%A literal '%' character.

Some conversion specifications can be modified by preceding the conversion specifier character by the E or O modifier to indicate that an alternative format should be used. If the alternative format or specification does not exist for the current locale, the behavior will be as if the unmodified conversion specification were used. (SU) The Single UNIX Specification mentions %Ec, %EC, %Ex, %EX, %Ey, %EY, %Od, %Oe, %OH, %OI, %Om, %OM, %OS, %Ou, %OU, %OV, %Ow, %OW, %Oy, where the effect of the O modifier is to use alternative numeric symbols (say, roman numerals), and that of the E modifier is to use a locale-dependent alternative representation.

Some examples using this method:

FormatMBS(format as string, value as Double, locale as string = "") as string
global method, Currency, Date and Time Format, MBS Util Plugin (Locale),
Plugin version: 13.0, Mac: Yes, Win: Yes, Linux: Yes, Console & Web: Yes, Feedback.

Function: Formats a double value.
Example:
MsgBox FormatMBS("%1.2f", 12.345, "de_DE")
Notes:
locale is the name of the locale to use. You can pass empty string to use default/current locale.
Format is a format string like for printf command in C.

The FormatMBS formats the value under control of the format. The format is a character string which contains three types of objects: plain characters, which are simply copied to standard output, character escape sequences which are converted and copied to the standard output, and format specifications, each of which causes printing of the next successive argument.

Character escape sequences are in backslash notation as defined in the ANSI X3.159-1989 ("ANSI C89"), with extensions. The characters and their meanings are as follows:

\aWrite a <bell> character.
\bWrite a <backspace> character.
\cIgnore remaining characters in this string.
\fWrite a <form-feed> character.
\nWrite a <new-line> character.
\rWrite a <carriage return> character.
\tWrite a <tab> character.
\vWrite a <vertical tab> character.
\'Write a <single quote> character.
\\Write a backslash character.
\num or \0numWrite an 8-bit character whose ASCII value is the 1-, 2-, or 3-digit octal number num.

Each format specification is introduced by the percent character (''%''). The remainder of the format specification includes, in the following order:

Zero or more of the following flags:

Some examples using this method:

Some FAQ entries about this method:

ParseDateMBS(format as string, text as string, byref value as date, locale as string = "") as boolean
global method, Currency, Date and Time Format, MBS Util Plugin (Locale),
Plugin version: 17.1, Mac: Yes, Win: Yes, Linux: Yes, Console & Web: Yes, Feedback.

Function: Parses a date.
Example:
dim s as string = "2013-11-12 18:31:01"
dim f as string = "%Y-%m-%d %H:%M:%S"
dim d as date

if ParseDateMBS(f, s, d) then
MsgBox d.LongDate + " "+ d.LongTime
end if
Notes:
locale is the name of the locale to use. You can pass empty string to use default/current locale.
Format is a format string like for strftime command in C.

On success returns true. But even for half parsed dates you can find values in date.
Locale not supported on Windows.
The plugin does not support parsing time zones.

The ParseDateMBS function is the converse function to FormateDateMBS and converts the character string pointed to by s to values which are stored in the date, using the format specified by format. Here format is a character string that consists of field descriptors and text characters, reminiscent of scanf (in C++). Each field descriptor consists of a % character followed by another character that specifies the replacement for the field descriptor. All other characters in the format string must have a matching character in the input string, except for whitespace, which matches zero or more whitespace characters in the input string. There should be whitespace or other alphanumeric characters between any two field descriptors.

The strptime() function processes the input string from left to right. Each of the three possible input elements (whitespace, literal, or format) are handled one after the other. If the input cannot be matched to the format string the function stops. The remainder of the format and input strings are not processed.

The supported input field descriptors are listed below. In case a text string (such as a weekday or month name) is to be matched, the comparison is case insensitive. In case a number is to be matched, leading zeros are permitted but not required.

%%The % character.
%a or %AThe weekday name according to the current locale, in abbreviated form or the full name.
%b or %B or %hThe month name according to the current locale, in abbreviated form or the full name.
%cThe date and time representation for the current locale.
%CThe century number (0-99).
%d or %eThe day of month (1-31).
%DEquivalent to %m/%d/%y. (This is the American style date, very confusing to non-Americans, especially since %d/%m/%y is widely used in Europe. The ISO 8601 standard format is %Y-%m-%d.)
%HThe hour (0-23).
%IThe hour on a 12-hour clock (1-12).
%jThe day number in the year (1-366).
%mThe month number (1-12).
%MThe minute (0-59).
%nArbitrary whitespace.
%pThe locale's equivalent of AM or PM. (Note: there may be none.)
%rThe 12-hour clock time (using the locale's AM or PM). In the POSIX locale equivalent to %I:%M:%S %p. If t_fmt_ampm is empty in the LC_TIME part of the current locale then the behavior is undefined.
%REquivalent to %H:%M.
%SThe second (0-60; 60 may occur for leap seconds; earlier also 61 was allowed).
%tArbitrary whitespace.
%TEquivalent to %H:%M:%S.
%UThe week number with Sunday the first day of the week (0-53). The first Sunday of January is the first day of week 1.
%wThe weekday number (0-6) with Sunday = 0.
%WThe week number with Monday the first day of the week (0-53). The first Monday of January is the first day of week 1.
%xThe date, using the locale's date format.
%XThe time, using the locale's time format.
%yThe year within century (0-99). When a century is not otherwise specified, values in the range 69-99 refer to years in the twentieth century (1969-1999); values in the range 00-68 refer to years in the twenty-first century (2000-2068).
%YThe year, including century (for example, 1991).

Some field descriptors can be modified by the E or O modifier characters to indicate that an alternative format or specification should be used. If the alternative format or specification does not exist in the current locale, the unmodified field descriptor is used.
The E modifier specifies that the input string may contain alternative locale-dependent versions of the date and time representation:

%EcThe locale's alternative date and time representation.
%ECThe name of the base year (period) in the locale's alternative representation.
%ExThe locale's alternative date representation.
%EXThe locale's alternative time representation.
%EyThe offset from %EC (year only) in the locale's alternative representation.
%EYThe full alternative year representation. The O modifier specifies that the numerical input may be in an alternative locale-dependent format:
%Od or %OeThe day of the month using the locale's alternative numeric symbols; leading zeros are permitted but not required.
%OHThe hour (24-hour clock) using the locale's alternative numeric symbols.
%OIThe hour (12-hour clock) using the locale's alternative numeric symbols.
%OmThe month using the locale's alternative numeric symbols.
%OMThe minutes using the locale's alternative numeric symbols.
%OSThe seconds using the locale's alternative numeric symbols.
%OUThe week number of the year (Sunday as the first day of the week) using the locale's alternative numeric symbols.
%OwThe number of the weekday (Sunday=0) using the locale's alternative numeric symbols.
%OWThe week number of the year (Monday as the first day of the week) using the locale's alternative numeric symbols.
%OyThe year (offset from %C) using the locale's alternative numeric symbols.

Returns true on success. If the functions fails to match all of the format string and therefore an error occurred the function returns false.

Before libc 5.4.13 whitespace (and the 'n' and 't' specifications) was not handled, no 'E' and 'O' locale modifier characters were accepted, and the 'C' specification was a synonym for the 'c' specification.

The 'y' (year in century) specification is taken to specify a year in the 20th century by libc4 and libc5. It is taken to be a year in the range 1950-2049 by glibc 2.0. It is taken to be a year in 1969-2068 since glibc 2.1.

For reasons of symmetry, glibc tries to support for ParseDateMBS the same format characters as for FormatDateMBS. (In most cases the corresponding fields are parsed, but no field in tm is changed.) This leads to
%FEquivalent to %Y-%m-%d, the ISO 8601 date format.
%gThe year corresponding to the ISO week number, but without the century (0-99).
%GThe year corresponding to the ISO week number. (For example, 1991.)
%uThe day of the week as a decimal number (1-7, where Monday = 1).
%VThe ISO 8601:1988 week number as a decimal number (1-53). If the week (starting on Monday) containing 1 January has four or more days in the new year, then it is considered week 1. Otherwise, it is the last week of the previous year, and the next week is week 1.
%zAn RFC-822/ISO 8601 standard timezone specification.
%ZThe timezone name.

Similarly, because of GNU extensions to FormatDateMBS, %k is accepted as a synonym for %H, and %l should be accepted as a synonym for %I, and %P is accepted as a synonym for %p. Finally
%sThe number of seconds since the Epoch, 1970-01-01 00:00:00 +0000 (UTC). Leap seconds are not counted unless leap second support is available.

The glibc implementation does not require whitespace between two field descriptors.

The items on this page are in the following plugins: MBS Util Plugin.




Links
MBS Realbasic tutorial videos