2014-02-20 4 views
2

다음과 같은 형식으로 일본어 날짜 (JDate)를받습니다. 어떻게 월 단위로 날짜와 연도를 확인할 수 있습니까?일본어로 된 날짜 확인

DateTuple = form_util:get_jdate_val("F_01_0070", Req), %%Get Jdate from Request 

이 기능은 다음과 같은 형식으로 JDate DateTuple를 반환

%%DateTuple 
{era,4,year,26, month,45,day,11}. 

%%Here era=4, year=26, invalid month=45 and Date=11. 
%%Where era number is calculated from this: 
era_tuple ={"4": "平成","3":"昭和", "2" :"大正", "1": "明治"} 

지금 JDate는 {상태, DateTuple}를 반환하는 유효성을 검사하는 방법에 대해 설명합니다. 나는 일본의 시대와 해의 관계를 모른다.

일본어 날짜를 쉽게 확인할 수 있습니까? Air Client를 사용하고 있기 때문에 프론트 엔드 자바 스크립트를 사용하여 처리하기가 상당히 복잡합니다.

미리 감사드립니다.

답변

1
-module(jdate). 
-export([to_jdate/1]). 

-define(HEISEI, 4). 
-define(HEISEI_START_YEAR, 1989). 
-define(HEISEI_START_MONTH, 1). 
-define(HEISEI_START_DAY, 8). 
-define(SHOWA, 3). 
-define(SHOWA_START_YEAR, 1926). 
-define(SHOWA_START_MONTH, 12). 
-define(SHOWA_START_DAY, 25). 
-define(SHOWA_LAST_YEAR, 64). 
-define(TAISHOU, 2). 
-define(TAISHOU_START_YEAR, 1912). 
-define(TAISHOU_START_MONTH, 7). 
-define(TAISHOU_START_DAY, 30). 
-define(TAISHOU_LAST_YEAR, 15). 
-define(MEIJI, 1). 
-define(MEIJI_START_YEAR, 1868). 
-define(MEIJI_START_MONTH, 1). 
-define(MEIJI_START_DAY, 1). 
-define(MEIJI_LAST_YEAR, 45). 
-define(JP_HOUR_OFFSET, 9). 

% Converts a datetime to a Japanese Year, Month, and Day (assumes the datetime is already in Japanese locale). 
to_jdate({era, Era, year, Year, month, Month, day, Day}) -> 
    {Era, Year, Month, Day}; 
to_jdate([{era, Era}, {year, Year}, {month, Month}, {day, Day}]) -> 
    {Era, Year, Month, Day}; 
to_jdate({_, _, _} = Timestamp) -> 
    io:format("timestamp: ~p~n", [Timestamp]), 
    Datetime = calendar:now_to_local_time(Timestamp), 
    io:format("datetime: ~p~n", [Datetime]), 
    to_jdate(Datetime); 
to_jdate({{Year, Month, Day}, {Hour, Minute, Second}}) when is_integer(Year) and 
                  is_integer(Month) and 
                  is_integer(Day) and 
                  is_integer(Hour) and 
                  is_integer(Minute) and 
                  is_integer(Second) -> 
    if 
     Year > ?HEISEI_START_YEAR -> 
      {?HEISEI, Year - ?HEISEI_START_YEAR + 1, Month, Day}; 
     Year =:= ?HEISEI_START_YEAR -> 
      if 
       Month =:= ?HEISEI_START_MONTH -> 
        if 
         Day < ?HEISEI_START_DAY -> 
          {?SHOWA, ?SHOWA_LAST_YEAR, Month, Day}; 
         true -> 
          {?HEISEI, 1, Month, Day} 
        end; 
       true -> 
        {?HEISEI, 1, Month, Day} 
      end; 
     Year > ?SHOWA_START_YEAR -> 
      {?SHOWA, Year - ?SHOWA_START_YEAR + 1, Month, Day}; 
     Year =:= ?SHOWA_START_YEAR -> 
      if 
       Month < ?SHOWA_START_MONTH -> 
        {?TAISHOU, ?TAISHOU_LAST_YEAR, Month, Day}; 
       Day >= ?SHOWA_START_DAY -> 
        {?SHOWA, 1, Month, Day}; 
       true -> 
        {?TAISHOU, ?TAISHOU_LAST_YEAR, Month, Day} 
      end; 
     Year > ?TAISHOU_START_YEAR -> 
      {?TAISHOU, Year - ?TAISHOU_START_YEAR + 1, Month, Day}; 
     Year =:= ?TAISHOU_START_YEAR -> 
      if 
       Month < ?TAISHOU_START_MONTH -> 
        {?MEIJI, ?MEIJI_LAST_YEAR, Month, Day}; 
       Month > ?TAISHOU_START_MONTH -> 
        {?TAISHOU, Year - ?TAISHOU_START_YEAR + 1, Month, Day}; 
       true -> 
        if 
         Day >= ?TAISHOU_START_DAY -> 
          {?TAISHOU, 1, Month, Day}; 
         true -> 
          {?MEIJI, ?MEIJI_LAST_YEAR, Month, Day} 
        end 
      end; 
     true -> 
      {?MEIJI, Year - ?MEIJI_START_YEAR + 1, Month, Day}    
    end; 
to_jdate(undefined) -> 
    {undefined, undefined, undefined, undefined}. 

그러나 이것은 평소와 같이 월 및 날짜 유효성 검사를 포함하지 않습니다. 일단 내가 끝내면 나는 그것을 포함 할 것이다.