Browse Source

部分代码整理

master
SisMaker 4 years ago
parent
commit
b3607d8811
9 changed files with 234 additions and 90 deletions
  1. +1
    -1
      README.md
  2. +15
    -1
      include/utTime.hrl
  3. +9
    -1
      src/md5/utMd5.erl
  4. +7
    -11
      src/srvNodeMgr/mtop.erl
  5. +2
    -1
      src/srvNodeMgr/utVMInfo.erl
  6. +12
    -18
      src/stackStrace/utParseStack.erl
  7. +33
    -0
      src/testCase/utMakeExport.erl
  8. +148
    -54
      src/timeDate/utTime.erl
  9. +7
    -3
      src/uuid/utUuid.erl

+ 1
- 1
README.md View File

@ -30,7 +30,7 @@
# timeData目录
获取各种本地时间与世界时间,以及本地时间与世界时间相互转换的时间函数封装
# uuidMd5 目录
# md5 目录
封装了Md5UUid的函数
# comMisc目录

+ 15
- 1
include/utTime.hrl View File

@ -4,4 +4,18 @@
-define(SECS_WEEK, 604800). %%
-define(DAYS_NO_LEAP_YEAR, 365). %%
-define(DAYS_LEAP_YEAR, 366). %%
-define(SECS_1970, 62167219200). %% utc 1970
-define(SECS_1970, 62167219200). %% utc 1970
-type year() :: non_neg_integer().
-type month() :: 1..12.
-type day() :: 1..31.
-type hour() :: 0..23.
-type minute() :: 0..59.
-type second() :: 0..59.
-type date() :: {year(), month(), day()}.
-type time() :: {hour(), minute(), second()}.
-type datetime() :: {date(), time()}.
-type timestamp() :: non_neg_integer(). %%
-type week() :: 1..7.
-type weekCycle() :: 1..53. %% 53
-type yearWeekCycle() :: {year(), weekCycle()}.

src/uuidMd5/utMd5.erl → src/md5/utMd5.erl View File

@ -1,6 +1,14 @@
-module(utMd5).
-compile([export_all, nowarn_export_all]).
-export([
getMd5/1 %% md5码
, getMd5Hex/1 %% hex str格式的Md5码
, getMd5HexBin/1 %% hex binary Md5码
, md5BinToHex/1 %% md5 to hex str
, md5BinToHexBin/1 %% %% md5 to hex binary
, hexToMd5Bin/1 %% hex str to md5
, hexBinToMd5Bin/1 %% %% hex binary to md5
]).
-spec getMd5(Str :: iodata()) -> binary().
getMd5(Str) ->

+ 7
- 11
src/srvNodeMgr/mtop.erl View File

@ -21,30 +21,26 @@
-define(PROCFORM, "~-15w~-20s~8w~8w~8w~8w ~-20s~n").
-record(mtop_info,
{now = {0, 0, 0},
-record(mtop_info, {
now = {0, 0, 0},
n_procs = 0,
wall_clock = {0, 0},
runtime = {0, 0},
run_queue = 0,
alloc_areas = [],
memi = [{total, 0},
{processes, 0},
{ets, 0},
{atom, 0},
{code, 0},
{binary, 0}],
memi = [{total, 0}, {processes, 0}, {ets, 0}, {atom, 0}, {code, 0}, {binary, 0}],
procinfo = []
}).
-record(mtop_proc_info,
{pid,
-record(mtop_proc_info, {
pid,
mem = 0,
reds = 0,
name,
runtime = 0,
cf,
mq = 0}).
mq = 0
}).
-record(opts, {lines = 10, sort = msg_q}).

+ 2
- 1
src/srvNodeMgr/utVMInfo.erl View File

@ -51,7 +51,8 @@ etop_stop() ->
%% process做gc
%% gc不过来
gc_all() ->
[erlang:garbage_collect(Pid) || Pid <- processes()].
[erlang:garbage_collect(Pid) || Pid <- processes()],
ok.
%% MFA
%% :

+ 12
- 18
src/stackStrace/utParseStack.erl View File

@ -1,7 +1,13 @@
-module(utParseStack).
-include("utParseStack.hrl").
-compile([export_all, nowarn_export_all]).
-export([
parseStack/1 %%
, parseStack/3 %% Class Reason
, printStack/1 %%
, testStack/1 %%
]).
%% stacktrace{ModuleFunctionArityLocation}
%% Arity: Arity字段可以是该函数调用的参数列表arity整数
@ -10,26 +16,14 @@
%% [{file, , }, {line, , > 0} :
%% term序列化, term转为string
term_to_string(Bin) when is_binary(Bin) ->
termToStr(Bin) when is_binary(Bin) ->
binary_to_list(Bin);
term_to_string(Term) ->
termToStr(Term) ->
case catch io_lib:format("~w", [Term]) of
{'EXIT', _} -> lists:flatten(io_lib:format("~p", [Term]));
GoodString -> lists:flatten(GoodString)
end.
%% term反序列化, string转换为term
string_to_term(String) ->
case erl_scan:string(String ++ ".") of
{ok, Tokens, _} ->
case erl_parse:parse_term(Tokens) of
{ok, Term} -> Term;
_Err -> String
end;
_Error ->
undefined
end.
parseStack(Stacktrace, Class, Reason) ->
CR = io_lib:format("~n Class:~s~n Reason:~p~n Stacktrace:", [Class, Reason]),
[CR | parseStack(Stacktrace)].
@ -38,11 +32,11 @@ parseStack(Stacktrace) ->
[begin
case Location of
[] ->
[<<"\n ">>, atom_to_list(Mod), <<":">>, atom_to_list(Func), <<"(">>, term_to_string(Arity), <<")">>];
[<<"\n ">>, atom_to_list(Mod), <<":">>, atom_to_list(Func), <<"(">>, termToStr(Arity), <<")">>];
[{file, File}, {line, Line}] ->
[<<"\n ">>, atom_to_list(Mod), <<":">>, atom_to_list(Func), <<"/">>, integer_to_binary(Arity), <<" (">>, File, <<":">>, integer_to_binary(Line), <<")">>];
_ ->
[<<"\n ">>, atom_to_list(Mod), <<":">>, atom_to_list(Func), <<" (">>, term_to_string(Arity), <<")">>, term_to_string(Location)]
[<<"\n ">>, atom_to_list(Mod), <<":">>, atom_to_list(Func), <<" (">>, termToStr(Arity), <<")">>, termToStr(Location)]
end
end || {Mod, Func, Arity, Location} <- Stacktrace
].
@ -60,7 +54,7 @@ bad_arity() ->
bad_arg(ErrArgs) ->
integer_to_list(ErrArgs).
test11(Index) ->
testStack(Index) ->
application:set_env(lager, reverse_pretty_stacktrace, false),
try
case Index of

+ 33
- 0
src/testCase/utMakeExport.erl View File

@ -0,0 +1,33 @@
-module(utMakeExport).
-export([makeExport/1]).
makeExport(SrcFile) ->
case file:open(SrcFile, [read, binary]) of
{ok, IoDevice} ->
BinStr = doMathEveryLine(IoDevice, "", <<>>),
file:close(IoDevice),
file:write_file("export.config", BinStr);
_ ->
false
end.
doMathEveryLine(IoDevice, Comment, BinStr) ->
case file:read_line(IoDevice) of
{ok, Data} ->
case re:run(Data, "%%") of
{match, _} ->
doMathEveryLine(IoDevice, Data, BinStr);
_ ->
case re:run(Data, "-spec") of
{match, _} ->
{ok, DataFun} = file:read_line(IoDevice),
DataFunStr = binary:replace(DataFun, <<"->\n">>, <<"">>),
doMathEveryLine(IoDevice, "", <<BinStr/binary, DataFunStr/binary, "\t\t\t\t", Comment/binary>>);
_ ->
doMathEveryLine(IoDevice, Comment, BinStr)
end
end;
_ ->
BinStr
end.

+ 148
- 54
src/timeDate/utTime.erl View File

@ -1,27 +1,112 @@
-module(utTime).
-include("utTime.hrl").
-compile([export_all, nowarn_export_all]).
-type year() :: non_neg_integer().
-type month() :: 1..12.
-type day() :: 1..31.
-type hour() :: 0..23.
-type minute() :: 0..59.
-type second() :: 0..59.
-type date() :: {year(), month(), day()}.
-type time() :: {hour(), minute(), second()}.
-type datetime() :: {date(), time()}.
-type timestamp() :: non_neg_integer(). %%
-type week() :: 1..7.
-type weekCycle() :: 1..53. %% 53
-type yearWeekCycle() :: {year(), weekCycle()}.
-import(calendar,
[
day_of_the_week/1
, iso_week_number/1
, date_to_gregorian_days/1
-import(calendar, [day_of_the_week/1, iso_week_number/1, date_to_gregorian_days/1]).
-export([
now/0 %%
, nowMs/0 %%
, curDateTime/0 %%
, curDate/0 %%
, curTime/0 %%
, weekDay/0 %%
, weekDay/1 %% Data是星期几
, weekDay/3 %%
, weekCycle/0 %%
, weekCycle/1 %% Date
, secToLDateTime/1 %% datetime()
, secToUDateTime/1 %% datetime()
, lDateTimeToSec/1 %% datetime()
, uDateTimeToSec/1 %% datetime()
, timeZoneDiff/0 %% UTC时区
, countLDay/1 %% 1970Sec
, countUDay/1 %% 1970Sec
, isSameLDay/2 %%
, isSameUDay/2 %%
, countLWeek/1 %% 1970Sec
, countUWeek/1 %% 1970Sec
, isSameLWeek/2 %%
, isSameUWeek/2 %%
, isSameLMonth/2 %%
, isSameUMonth/2 %%
, countLDay/2 %% 1970Sec ZeroOffset为零点偏移时间
, countUDay/2 %% 1970Sec ZeroOffset为零点偏移时间
, isSameLDay/3 %% ZeroOffset为零点偏移时间
, isSameUDay/3 %% ZeroOffset为零点偏移时间
, countLWeek/2 %% 1970Sec ZeroOffset为零点偏移时间
, countUWeek/2 %% 1970Sec ZeroOffset为零点偏移时间
, isSameLWeek/3 %% ZeroOffset为零点偏移时间
, isSameUWeek/3 %% ZeroOffset为零点偏移时间
, isSameLMonth/3 %% ZeroOffset为零点偏移时间
, isSameUMonth/3 %% ZeroOffset为零点偏移时间
, hourBegin/0 %%
, hourBegin/1 %% Sec所在小时开始时间戳
, hourEnd/0 %%
, hourEnd/1 %% Sec所在小时结束时间戳
, dayLBegin/0 %%
, dayLBegin/1 %% Sec所在天开始时间戳
, dayUBegin/0 %% Sec所在天开始时间戳
, dayUBegin/1 %% Sec所在天开始时间戳
, dayLEnd/0 %%
, dayLEnd/1 %% Sec所在天结束时间戳
, dayUEnd/0 %%
, dayUEnd/1 %% Sec所在天结束时间戳
, dayLBeginEnd/0 %%
, dayLBeginEnd/1 %% Sec所在天开始结束时间戳
, dayUBeginEnd/0 %%
, dayUBeginEnd/1 %% Sec所在天开始结束时间戳
, weekLBegin/0 %%
, weekLBegin/1 %% Sec所在周开始时间戳
, weekUBegin/0 %%
, weekUBegin/1 %% Sec所在周的开始时间戳
, weekLEnd/0 %%
, weekLEnd/1 %% Sec所在周的结束时间戳
, weekUEnd/0 %%
, weekUEnd/1 %% Sec所在周的结束时间戳
, weekLBeginEnd/0 %%
, weekLBeginEnd/1 %% Sec所在周的开始结束时间戳
, weekUBeginEnd/0 %%
, weekUBeginEnd/1 %% Sec所在周的开始结束时间戳
, monthLBegin/0 %%
, monthLBegin/1 %% Sec所在月的开始时间戳
, monthUBegin/0 %%
, monthUBegin/1 %% Sec所在月的开始时间戳
, monthLEnd/0 %%
, monthLEnd/1 %% Sec所在月的结束时间戳
, monthUEnd/0 %%
, monthUEnd/1 %% Sec所在月的结束时间戳
, isLeapYear/1 %%
, monthDay/2 %%
, monthSecs/2 %%
, monthLBeginEnd/0 %%
, monthLBeginEnd/1 %% Sec所在月的开始结束时间戳
, monthUBeginEnd/0 %%
, monthUBeginEnd/1 %% Sec所在月的开始结束时间戳
, sWeekName/1 %%
, lWeekName/1 %%
, sMonthName/1 %%
, lMonthName/1 %%
, dateNumber/0 %% version
, dateNumber/1 %% version
, dateNumber/3 %% version
, numberDate/1 %% dateNumber
, secToDayTime/1 %% time()
, diffLDateTimeSec/2 %% datetime()
, diffUDateTimeSec/2 %% datetime()
, diffLDateTimeDayTime/2 %% datetime() daytime()
, diffUDateTimeDayTime/2 %% datetime() daytime()
, diffSecs/2 %% daytime()
, timeToSecs/1 %% time() Sec
, daysInYear/1 %% Date为该年的哪一天
, dateToStr/1 %% Data to Str
, dateToStr/3 %% Data to Str
, dateToStr/2 %% Data to Str
, dateToStr/4 %% Data to Str
, timeToStr/1 %% time to Str
, timeToStr/3 %% time to Str
, timeToStr/2 %% time to Str
, timeToStr/4 %% time to Str
, dateTimeStr/1 %% datetime to Str
]).
%%
@ -75,23 +160,23 @@ weekCycle(Date) ->
calendar:iso_week_number(Date).
%% datetime()
-spec secToLocalTime(Sec :: timestamp()) -> datetime().
secToLocalTime(Ses) ->
-spec secToLDateTime(Sec :: timestamp()) -> datetime().
secToLDateTime(Ses) ->
erlang:universaltime_to_localtime(erlang:posixtime_to_universaltime(Ses)).
%% datetime()
-spec secToUniversalTime(Sec :: timestamp()) -> datetime().
secToUniversalTime(Ses) ->
-spec secToUDateTime(Sec :: timestamp()) -> datetime().
secToUDateTime(Ses) ->
erlang:posixtime_to_universaltime(Ses).
%% datetime()
-spec localTimeToSec(LocalDate :: datetime()) -> timestamp().
localTimeToSec(LocalDate) ->
-spec lDateTimeToSec(LocalDate :: datetime()) -> timestamp().
lDateTimeToSec(LocalDate) ->
erlang:universaltime_to_posixtime(erlang:localtime_to_universaltime(LocalDate)).
%% datetime()
-spec universalTimeToSec(UniversalTime :: datetime()) -> timestamp().
universalTimeToSec(UniversalTime) ->
-spec uDateTimeToSec(UniversalTime :: datetime()) -> timestamp().
uDateTimeToSec(UniversalTime) ->
erlang:universaltime_to_posixtime(UniversalTime).
%% UTC时区
@ -145,15 +230,15 @@ isSameUWeek(Sec1, Sec2) ->
%%
-spec isSameLMonth(Sec1 :: timestamp(), Sec2 :: timestamp()) -> boolean().
isSameLMonth(Sec1, Sec2) ->
{{Year1, Month1, _Day1}, _Time1} = secToLocalTime(Sec1),
{{Year2, Month2, _Day2}, _Time2} = secToLocalTime(Sec2),
{{Year1, Month1, _Day1}, _Time1} = secToLDateTime(Sec1),
{{Year2, Month2, _Day2}, _Time2} = secToLDateTime(Sec2),
Month1 =:= Month2 andalso Year1 =:= Year2.
%%
-spec isSameUMonth(Sec1 :: timestamp(), Sec2 :: timestamp()) -> boolean().
isSameUMonth(Sec1, Sec2) ->
{{Year1, Month1, _Day1}, _Time1} = secToUniversalTime(Sec1),
{{Year2, Month2, _Day2}, _Time2} = secToUniversalTime(Sec2),
{{Year1, Month1, _Day1}, _Time1} = secToUDateTime(Sec1),
{{Year2, Month2, _Day2}, _Time2} = secToUDateTime(Sec2),
Month1 =:= Month2 andalso Year1 =:= Year2.
%% 1970Sec ZeroOffset为零点偏移时间
@ -201,15 +286,15 @@ isSameUWeek(Sec1, Sec2, ZeroOffset) ->
%% ZeroOffset为零点偏移时间
-spec isSameLMonth(Sec1 :: timestamp(), Sec2 :: timestamp(), ZeroOffset :: timestamp()) -> boolean().
isSameLMonth(Sec1, Sec2, ZeroOffset) ->
{{Year1, Month1, _Day1}, _Time1} = secToLocalTime(Sec1 - ZeroOffset),
{{Year2, Month2, _Day2}, _Time2} = secToLocalTime(Sec2 - ZeroOffset),
{{Year1, Month1, _Day1}, _Time1} = secToLDateTime(Sec1 - ZeroOffset),
{{Year2, Month2, _Day2}, _Time2} = secToLDateTime(Sec2 - ZeroOffset),
Month1 =:= Month2 andalso Year1 =:= Year2.
%% ZeroOffset为零点偏移时间
-spec isSameUMonth(Sec1 :: timestamp(), Sec2 :: timestamp(), ZeroOffset :: timestamp()) -> boolean().
isSameUMonth(Sec1, Sec2, ZeroOffset) ->
{{Year1, Month1, _Day1}, _Time1} = secToUniversalTime(Sec1 - ZeroOffset),
{{Year2, Month2, _Day2}, _Time2} = secToUniversalTime(Sec2 - ZeroOffset),
{{Year1, Month1, _Day1}, _Time1} = secToUDateTime(Sec1 - ZeroOffset),
{{Year2, Month2, _Day2}, _Time2} = secToUDateTime(Sec2 - ZeroOffset),
Month1 =:= Month2 andalso Year1 =:= Year2.
%%
@ -378,16 +463,16 @@ weekUBeginEnd(Sec) ->
-spec monthLBegin() -> timestamp().
monthLBegin() ->
Sec = erlang:system_time(second),
{{Year, Month, _Day}, _Time} = secToLocalTime(Sec),
{{Year, Month, _Day}, _Time} = secToLDateTime(Sec),
MonthStartDateTime = {{Year, Month, 1}, {0, 0, 0}},
localTimeToSec(MonthStartDateTime).
lDateTimeToSec(MonthStartDateTime).
%% Sec所在月的开始时间戳
-spec monthLBegin(Sec :: timestamp()) -> timestamp().
monthLBegin(Sec) ->
{{Year, Month, _Day}, _Time} = secToLocalTime(Sec),
{{Year, Month, _Day}, _Time} = secToLDateTime(Sec),
MonthStartDateTime = {{Year, Month, 1}, {0, 0, 0}},
localTimeToSec(MonthStartDateTime).
lDateTimeToSec(MonthStartDateTime).
%%
-spec monthUBegin() -> timestamp().
@ -408,18 +493,18 @@ monthUBegin(Sec) ->
-spec monthLEnd() -> timestamp().
monthLEnd() ->
Sec = erlang:system_time(second),
{{Year, Month, _Day}, _Time} = secToLocalTime(Sec),
{{Year, Month, _Day}, _Time} = secToLDateTime(Sec),
MonthDay = monthDay(Year, Month),
MonthEndDateTime = {{Year, Month, MonthDay}, {23, 59, 59}},
localTimeToSec(MonthEndDateTime).
lDateTimeToSec(MonthEndDateTime).
%% Sec所在月的结束时间戳
-spec monthLEnd(Sec :: timestamp()) -> timestamp().
monthLEnd(Sec) ->
{{Year, Month, _Day}, _Time} = secToLocalTime(Sec),
{{Year, Month, _Day}, _Time} = secToLDateTime(Sec),
MonthDay = monthDay(Year, Month),
MonthEndDateTime = {{Year, Month, MonthDay}, {23, 59, 59}},
localTimeToSec(MonthEndDateTime).
lDateTimeToSec(MonthEndDateTime).
%%
-spec monthUEnd() -> timestamp().
@ -475,17 +560,17 @@ monthSecs(_, _) ->
-spec monthLBeginEnd() -> timestamp().
monthLBeginEnd() ->
Sec = erlang:system_time(second),
{{Year, Month, _Day}, _Time} = secToLocalTime(Sec),
{{Year, Month, _Day}, _Time} = secToLDateTime(Sec),
MonthStartDateTime = {{Year, Month, 1}, {0, 0, 0}},
Begin = localTimeToSec(MonthStartDateTime),
Begin = lDateTimeToSec(MonthStartDateTime),
{Begin, Begin + monthSecs(Year, Month)}.
%% Sec所在月的开始结束时间戳
-spec monthLBeginEnd(Sec :: timestamp()) -> timestamp().
monthLBeginEnd(Sec) ->
{{Year, Month, _Day}, _Time} = secToLocalTime(Sec),
{{Year, Month, _Day}, _Time} = secToLDateTime(Sec),
MonthStartDateTime = {{Year, Month, 1}, {0, 0, 0}},
Begin = localTimeToSec(MonthStartDateTime),
Begin = lDateTimeToSec(MonthStartDateTime),
{Begin, Begin + monthSecs(Year, Month)}.
%%
@ -593,25 +678,25 @@ secToDayTime(Secs) ->
%% datetime()
-spec diffLDateTimeSec(datetime(), datetime()) -> timestamp().
diffLDateTimeSec(DateTime1, DateTime2) ->
Secs = localTimeToSec(DateTime1) - localTimeToSec(DateTime2),
Secs = lDateTimeToSec(DateTime1) - lDateTimeToSec(DateTime2),
erlang:abs(Secs).
%% datetime()
-spec diffUDateTimeSec(datetime(), datetime()) -> timestamp().
diffUDateTimeSec(DateTime1, DateTime2) ->
Secs = universalTimeToSec(DateTime1) - universalTimeToSec(DateTime2),
Secs = uDateTimeToSec(DateTime1) - uDateTimeToSec(DateTime2),
erlang:abs(Secs).
%% datetime() daytime()
-spec diffLDateTimeDayTime(datetime(), datetime()) -> timestamp().
diffLDateTimeDayTime(DateTime1, DateTime2) ->
Secs = localTimeToSec(DateTime1) - localTimeToSec(DateTime2),
Secs = lDateTimeToSec(DateTime1) - lDateTimeToSec(DateTime2),
secToDayTime(erlang:abs(Secs)).
%% datetime() daytime()
-spec diffUDateTimeDayTime(datetime(), datetime()) -> timestamp().
diffUDateTimeDayTime(DateTime1, DateTime2) ->
Secs = universalTimeToSec(DateTime1) - universalTimeToSec(DateTime2),
Secs = uDateTimeToSec(DateTime1) - uDateTimeToSec(DateTime2),
secToDayTime(erlang:abs(Secs)).
%% daytime()
@ -627,48 +712,57 @@ timeToSecs({H, M, S}) ->
%% Date为该年的哪一天
-spec daysInYear(date()) -> integer().
daysInYear({Y, _, _} = Date) ->
date_to_gregorian_days(Date) - date_to_gregorian_days({Y, 1, 1}).
calendar:date_to_gregorian_days(Date) - calendar:date_to_gregorian_days({Y, 1, 1}).
%% Data to Str
-spec dateToStr(date()) -> string().
dateToStr({Year, Month, Day}) ->
S = io_lib:format("~B_~2.10.0B_~2.10.0B", [Year, Month, Day]),
lists:flatten(S).
%% Data to Str
-spec dateToStr(year(), month(), day()) -> string().
dateToStr(Year, Month, Day) ->
S = io_lib:format("~B_~2.10.0B_~2.10.0B", [Year, Month, Day]),
lists:flatten(S).
%% Data to Str
-spec dateToStr(date(), string()) -> string().
dateToStr({Year, Month, Day}, Separator) ->
S = io_lib:format("~B~w~2.10.0B~w~2.10.0B", [Year, Separator, Month, Separator, Day]),
lists:flatten(S).
%% Data to Str
-spec dateToStr(year(), month(), day(), string()) -> string().
dateToStr(Year, Month, Day, Separator) ->
S = io_lib:format("~B~w~2.10.0B~w~2.10.0B", [Year, Separator, Month, Separator, Day]),
lists:flatten(S).
%% time to Str
-spec timeToStr(time()) -> string().
timeToStr({Hour, Minute, Second}) ->
S = io_lib:format("~B:~2.10.0B:~2.10.0B", [Hour, Minute, Second]),
lists:flatten(S).
%% time to Str
-spec timeToStr(hour(), minute(), second()) -> string().
timeToStr(Hour, Minute, Second) ->
S = io_lib:format("~B:~2.10.0B:~2.10.0B", [Hour, Minute, Second]),
lists:flatten(S).
%% time to Str
-spec timeToStr(time(), string()) -> string().
timeToStr({Hour, Minute, Second}, Separator) ->
S = io_lib:format("~B~w~2.10.0B~w~2.10.0B", [Hour, Separator, Minute, Separator, Second]),
lists:flatten(S).
%% time to Str
-spec timeToStr(hour(), minute(), second(), string()) -> string().
timeToStr(Hour, Minute, Second, Separator) ->
S = io_lib:format("~B~w~2.10.0B~w~2.10.0B", [Hour, Separator, Minute, Separator, Second]),
lists:flatten(S).
%% datetime to Str
-spec dateTimeStr(datetime()) -> string().
dateTimeStr({{Year, Month, Day}, {Hour, Minute, Second}}) ->
S = io_lib:format("~B_~2.10.0B_~2.10.0B ~B:~2.10.0B:~2.10.0B", [Year, Month, Day, Hour, Minute, Second]),

src/uuidMd5/utUuid.erl → src/uuid/utUuid.erl View File

@ -1,6 +1,10 @@
-module(utUuid).
-compile([export_all, nowarn_export_all]).
-export([
randStr/1 %%
, uuid/0 %% UUID
, uuidHex/0 %% hex格式的唯一UUID
]).
-spec randStr(integer()) -> string().
randStr(Length) ->
@ -17,10 +21,10 @@ randStr(Length) ->
end
end || _ <- lists:seq(1, Length)].
-spec uuid() -> binary.
-spec uuid() -> binary().
uuid() ->
erlang:md5(term_to_binary({erlang:system_time(nanosecond), rand:uniform(134217727), make_ref()})).
-spec uuidHex() -> binary.
-spec uuidHex() -> binary().
uuidHex() ->
utMd5:getMd5Hex(term_to_binary({erlang:system_time(nanosecond), rand:uniform(134217727), make_ref()})).

Loading…
Cancel
Save