diff --git a/Base/JPL.Conversion.pas b/Base/JPL.Conversion.pas index ee0a82f..ca9d546 100644 --- a/Base/JPL.Conversion.pas +++ b/Base/JPL.Conversion.pas @@ -23,6 +23,8 @@ interface SysUtils, JPL.Strings; +type + TTimeUnit = (tuMillisecond, tuSecond, tuMinute, tuHour, tuDay {24h}); function BoolToStr(const b: Boolean; TrueStr: string = 'True'; FalseStr: string = 'False'): string; @@ -127,7 +129,7 @@ function TryHexToInt(Hex: string; var xInt: Int64): Boolean; overload; function TryHexToInt(Hex: string; var xInt: integer): Boolean; overload; function TryHexToByte(Hex: string; var xb: Byte): Boolean; -function TryGetMilliseconds(const NumStr: string; out MilliSeconds: Int64): Boolean; +function TryGetMilliseconds(const NumStr: string; out MilliSeconds: Int64; DefaultTimeUnit: TTimeUnit = tuMillisecond): Boolean; @@ -137,7 +139,7 @@ implementation JPL.TStr; -function TryGetMilliseconds(const NumStr: string; out MilliSeconds: Int64): Boolean; +function TryGetMilliseconds(const NumStr: string; out MilliSeconds: Int64; DefaultTimeUnit: TTimeUnit = tuMillisecond): Boolean; var s: string; dx64: Double; @@ -176,7 +178,16 @@ function TryGetMilliseconds(const NumStr: string; out MilliSeconds: Int64): Bool bDays := True; s := TStr.TrimFromEnd(s, 'd'); end - else bSeconds := True; + else + begin + // No time unit specified. Using DefaultTimeUnit + case DefaultTimeUnit of + tuSecond: bSeconds := True; + tuMinute: bMinutes := True; + tuHour: bHours := True; + tuDay: bDays := True; + end; + end; dx64 := 0; if (TStr.StartsWithHexPrefix(s)) or (Copy(s, 1, 1) = '%') then @@ -191,11 +202,8 @@ function TryGetMilliseconds(const NumStr: string; out MilliSeconds: Int64): Bool else if bHours then dx64 := dx64 * 1000 * 60 * 60 else if bDays then dx64 := dx64 * 1000 * 60 * 60 * 24; - //if dx64 > TIME_MAX then Exit; - MilliSeconds := Int64(Round(dx64)); Result := True; - end; function TryHexToByte(Hex: string; var xb: Byte): Boolean; diff --git a/Readme.md b/Readme.md index 2821704..82ec8ee 100644 --- a/Readme.md +++ b/Readme.md @@ -4,13 +4,10 @@ ![](https://tokei.rs/b1/github/jackdp/JPLib?category=files) ![visitors](https://visitor-badge.glitch.me/badge?page_id=jackdp.jplib) -Small library of Pascal units needed to compile my projects published on GitHub. +A library of general-purpose pascal units needed to compile my projects published on GitHub. Supported Delphi versions: **2009**, **2010**, **XE**, **XE2**, **XE3**, **XE4**, **XE5**, **XE6**, **XE7**, **XE8**, **10.0 Seattle**, **10.1 Berlin**, **10.2 Tokyo**, **10.3 Rio**, **10.4 Sydney**, **11.0 Alexandria**. -**Lazarus**: Required FPC version ~~3.0.4~~ **3.2.0** or newer. -**CodeTyphon**: Tested on CodeTyphon 7.00, 7.10, 7.20 with FPC 3.3.1 - ---- +**FPC** (Free Pascal Compiler): required version ~~3.0.4~~ **3.2.0** or newer. ## Installation @@ -19,16 +16,23 @@ The packages are "run-time" type and do not contain any components. The JPLib package must be installed if you want to install the [JPPack](https://github.com/jackdp/JPPack) components package. If you do not want to install JPPack, you can use JPLib without any installation. ---- - ## Hash Some units in the [Hash](./Hash) folder uses **HashLib4Pascal** library from and **Wolfgang Ehrhardt's** hashing units from ---- - ## License -The license for my work: **Public domain**. You can do with my code whatever you want without any limitations. +The license for my work: **public domain**. You can do with my code whatever you want without any limitations. + +But in some units I use code from other open source projects, so you should look at the PAS source files and license of the authors of these projects for more information. + +## Important changes + +A list of changes that may break existing code. -But, in some units I use code from other open source projects, so you should look at the PAS source files and license of the authors of these projects for more information. \ No newline at end of file +2022.08.06 +JPL.Conversion.pas +```pascal +function TryGetMilliseconds(const NumStr: string; out MilliSeconds: Int64; DefaultTimeUnit: TTimeUnit = tuMillisecond): Boolean; +``` +The `DefaultTimeUnit` parameter has been added. It specifies the default time unit to be used if it is not given in `NumStr`. Now the default unit is a **millisecond**, before the change it was a second. diff --git a/src_stats_PAS.txt b/src_stats_PAS.txt index c9c805e..ed4d9aa 100644 --- a/src_stats_PAS.txt +++ b/src_stats_PAS.txt @@ -1,7 +1,7 @@ Command line: TxtAn64 *.pas *.dpr *.lpr *.pp -r 1 -s -Processed files: 129 -Total size: 1.88 MB -Elapsed time: 00:00:00.072 -All lines: 63 523 -All blank lines: 12 104 -All not blank lines: 51 419 +Processed files: 130 +Total size: 1.89 MB +Elapsed time: 00:00:00.063 +All lines: 64 080 +All blank lines: 12 200 +All not blank lines: 51 880