rtime-serieschron

Formating timestamp in readable time format (days since into correct 360 day Calendar)


I have the following problem. I've got model data between the years 2006 and 2100, but every month has 30 days, that means the calendar format is 360_day. Is there the possibility, to change the calendar format in chron into this format? "This format" means, that I have 30 days for each month. With the method below, chron uses the normal calendar format.

The transformed timestamp starts at (12/Mar/2005 12:00:00) instead of the correct (1/Jan/2006 12:00:00) and uses the normal calendar format, which you can see, when you try out the code and use the subset.

time.reconf <- chron(time, origin = c(12, 1, 1949),format = c(dates = "dd/mm/yyyy", times = "h:m:s")) 

the following data is a subset of time:

 structure(c(20190.5, 20191.5, 20192.5, 20193.5, 20194.5, 20195.5, 
 20196.5, 20197.5, 20198.5, 20199.5, 20200.5, 20201.5, 20202.5, 
 20203.5, 20204.5, 20205.5, 20206.5, 20207.5, 20208.5, 20209.5, 
 20210.5, 20211.5, 20212.5, 20213.5, 20214.5, 20215.5, 20216.5, 
 20217.5, 20218.5, 20219.5, 20220.5, 20221.5, 20222.5, 20223.5, 
 20224.5, 20225.5, 20226.5, 20227.5, 20228.5, 20229.5, 20230.5, 
 20231.5, 20232.5, 20233.5, 20234.5, 20235.5, 20236.5, 20237.5, 
 20238.5, 20239.5, 20240.5, 20241.5, 20242.5, 20243.5, 20244.5, 
 20245.5, 20246.5, 20247.5, 20248.5, 20249.5, 20250.5, 20251.5, 
 20252.5, 20253.5, 20254.5, 20255.5, 20256.5, 20257.5, 20258.5, 
 20259.5, 20260.5, 20261.5, 20262.5, 20263.5, 20264.5, 20265.5, 
 20266.5, 20267.5, 20268.5, 20269.5, 20270.5, 20271.5, 20272.5, 
 20273.5, 20274.5, 20275.5, 20276.5, 20277.5, 20278.5, 20279.5, 
 20280.5, 20281.5, 20282.5, 20283.5, 20284.5, 20285.5, 20286.5, 
 20287.5, 20288.5, 20289.5, 20290.5, 20291.5, 20292.5, 20293.5, 
 20294.5, 20295.5, 20296.5, 20297.5, 20298.5, 20299.5, 20300.5, 
 20301.5, 20302.5, 20303.5, 20304.5, 20305.5, 20306.5, 20307.5, 
 20308.5, 20309.5, 20310.5, 20311.5, 20312.5, 20313.5, 20314.5, 
 20315.5, 20316.5, 20317.5, 20318.5, 20319.5, 20320.5, 20321.5, 
 20322.5, 20323.5, 20324.5, 20325.5, 20326.5, 20327.5, 20328.5, 
 20329.5, 20330.5, 20331.5, 20332.5, 20333.5, 20334.5, 20335.5, 
 20336.5, 20337.5, 20338.5, 20339.5, 20340.5, 20341.5, 20342.5, 
 20343.5, 20344.5, 20345.5, 20346.5, 20347.5, 20348.5, 20349.5, 
 20350.5, 20351.5, 20352.5, 20353.5, 20354.5, 20355.5, 20356.5, 
 20357.5, 20358.5, 20359.5, 20360.5, 20361.5, 20362.5, 20363.5, 
 20364.5, 20365.5, 20366.5, 20367.5, 20368.5, 20369.5, 20370.5, 
 20371.5, 20372.5, 20373.5, 20374.5, 20375.5, 20376.5, 20377.5, 
 20378.5, 20379.5, 20380.5, 20381.5, 20382.5, 20383.5, 20384.5, 
 20385.5, 20386.5, 20387.5, 20388.5, 20389.5, 20390.5, 20391.5, 
 20392.5, 20393.5, 20394.5, 20395.5, 20396.5, 20397.5, 20398.5, 
 20399.5, 20400.5, 20401.5, 20402.5, 20403.5, 20404.5, 20405.5, 
 20406.5, 20407.5, 20408.5, 20409.5, 20410.5, 20411.5, 20412.5, 
 20413.5, 20414.5, 20415.5, 20416.5, 20417.5, 20418.5, 20419.5, 
 20420.5, 20421.5, 20422.5, 20423.5, 20424.5, 20425.5, 20426.5, 
 20427.5, 20428.5, 20429.5, 20430.5, 20431.5, 20432.5, 20433.5, 
 20434.5, 20435.5, 20436.5, 20437.5, 20438.5, 20439.5, 20440.5, 
 20441.5, 20442.5, 20443.5, 20444.5, 20445.5, 20446.5, 20447.5, 
 20448.5, 20449.5, 20450.5, 20451.5, 20452.5, 20453.5, 20454.5, 
 20455.5, 20456.5, 20457.5, 20458.5, 20459.5, 20460.5, 20461.5, 
 20462.5, 20463.5, 20464.5, 20465.5, 20466.5, 20467.5, 20468.5, 
 20469.5, 20470.5, 20471.5, 20472.5, 20473.5, 20474.5, 20475.5, 
 20476.5, 20477.5, 20478.5, 20479.5, 20480.5, 20481.5, 20482.5, 
 20483.5, 20484.5, 20485.5, 20486.5, 20487.5, 20488.5, 20489.5, 
 20490.5, 20491.5, 20492.5, 20493.5, 20494.5, 20495.5, 20496.5, 
 20497.5, 20498.5, 20499.5, 20500.5, 20501.5, 20502.5, 20503.5, 
 20504.5, 20505.5, 20506.5, 20507.5, 20508.5, 20509.5, 20510.5, 
 20511.5, 20512.5, 20513.5, 20514.5, 20515.5, 20516.5, 20517.5, 
 20518.5, 20519.5, 20520.5, 20521.5, 20522.5, 20523.5, 20524.5, 
 20525.5, 20526.5, 20527.5, 20528.5, 20529.5, 20530.5, 20531.5, 
 20532.5, 20533.5, 20534.5, 20535.5, 20536.5, 20537.5, 20538.5, 
 20539.5, 20540.5, 20541.5, 20542.5, 20543.5, 20544.5, 20545.5, 
 20546.5, 20547.5, 20548.5, 20549.5, 20550.5, 20551.5, 20552.5, 
 20553.5, 20554.5, 20555.5, 20556.5, 20557.5, 20558.5, 20559.5, 
 20560.5, 20561.5, 20562.5, 20563.5, 20564.5, 20565.5, 20566.5, 
 20567.5, 20568.5, 20569.5, 20570.5, 20571.5, 20572.5, 20573.5, 
 20574.5, 20575.5, 20576.5, 20577.5, 20578.5, 20579.5), .Dim = 390L)

Solution

  • I've changed your time series into a normal vector

    time <- c(20190.5, 20191.5, 20192.5, 20193.5, 20194.5, 20195.5, 
              20196.5, 20197.5, 20198.5, 20199.5, 20200.5, 20201.5, 20202.5, 
              20203.5, 20204.5, 20205.5, 20206.5, 20207.5, 20208.5, 20209.5,
              ... 
              20567.5, 20568.5, 20569.5, 20570.5, 20571.5, 20572.5, 20573.5, 
              20574.5, 20575.5, 20576.5, 20577.5, 20578.5, 20579.5)
    

    Secondly, I've installed the PCICt package

    install.packages('PCICt')
    library(PCICt)
    

    Here you can set the parameters on 360

    cal <- "360_day"
    

    Set the start day, to 2006-01-01

    origin <- "2006-01-01"
    seconds.per.day <- 60*60*24
    

    And edit, the time series, If the structure, is the same as you've provided then (correct me if it is wrong), it should be correct to substract the first date, from all the other dates. thus : [ 20190.5, 20191.5, 20192.5, 20193.5 ...] will become [ 0 1 2 3 ... ] . thus, 0 is the same as 2006-01-01 and 1 is 2006-01-02 -- 2 is 2006-01-03 etc

    ts.dat.days <- time - time[1]
    origin.pcict <- as.PCICt(origin, cal)
    ts.dat.pcict <- origin.pcict + (ts.dat.days * seconds.per.day)
    

    print the series

    ts.dat.pcict
      [1] "2006-01-01" "2006-01-02" "2006-01-03" "2006-01-04" "2006-01-05"
      [6] "2006-01-06" "2006-01-07" "2006-01-08" "2006-01-09" "2006-01-10"
     [11] "2006-01-11" "2006-01-12" "2006-01-13" "2006-01-14" "2006-01-15"
     [16] "2006-01-16" "2006-01-17" "2006-01-18" "2006-01-19" "2006-01-20"
     [21] "2006-01-21" "2006-01-22" "2006-01-23" "2006-01-24" "2006-01-25"
     [26] "2006-01-26" "2006-01-27" "2006-01-28" "2006-01-29" "2006-01-30"
     [31] "2006-02-01" "2006-02-02" "2006-02-03" "2006-02-04" "2006-02-05"
     [36] "2006-02-06" "2006-02-07" "2006-02-08" "2006-02-09" "2006-02-10"
     [41] "2006-02-11" "2006-02-12" "2006-02-13" "2006-02-14" "2006-02-15"
     [46] "2006-02-16" "2006-02-17" "2006-02-18" "2006-02-19" "2006-02-20"
     [51] "2006-02-21" "2006-02-22" "2006-02-23" "2006-02-24" "2006-02-25"
     [56] "2006-02-26" "2006-02-27" "2006-02-28" "2006-02-29" "2006-02-30"
     [61] "2006-03-01" "2006-03-02" "2006-03-03" "2006-03-04" "2006-03-05"
     [66] "2006-03-06" "2006-03-07" "2006-03-08" "2006-03-09" "2006-03-10"
     [71] "2006-03-11" "2006-03-12" "2006-03-13" "2006-03-14" "2006-03-15"
     [76] "2006-03-16" "2006-03-17" "2006-03-18" "2006-03-19" "2006-03-20"
     [81] "2006-03-21" "2006-03-22" "2006-03-23" "2006-03-24" "2006-03-25"
     [86] "2006-03-26" "2006-03-27" "2006-03-28" "2006-03-29" "2006-03-30"
     [91] "2006-04-01" "2006-04-02" "2006-04-03" "2006-04-04" "2006-04-05"
     [96] "2006-04-06" "2006-04-07" "2006-04-08" "2006-04-09" "2006-04-10"
    [101] "2006-04-11" "2006-04-12" "2006-04-13" "2006-04-14" "2006-04-15"
    [106] "2006-04-16" "2006-04-17" "2006-04-18" "2006-04-19" "2006-04-20"
    [111] "2006-04-21" "2006-04-22" "2006-04-23" "2006-04-24" "2006-04-25"
    [116] "2006-04-26" "2006-04-27" "2006-04-28" "2006-04-29" "2006-04-30"
    [121] "2006-05-01" "2006-05-02" "2006-05-03" "2006-05-04" "2006-05-05"
    [126] "2006-05-06" "2006-05-07" "2006-05-08" "2006-05-09" "2006-05-10"
    [131] "2006-05-11" "2006-05-12" "2006-05-13" "2006-05-14" "2006-05-15"
    [136] "2006-05-16" "2006-05-17" "2006-05-18" "2006-05-19" "2006-05-20"
    [141] "2006-05-21" "2006-05-22" "2006-05-23" "2006-05-24" "2006-05-25"
    [146] "2006-05-26" "2006-05-27" "2006-05-28" "2006-05-29" "2006-05-30"
    [151] "2006-06-01" "2006-06-02" "2006-06-03" "2006-06-04" "2006-06-05"
    [156] "2006-06-06" "2006-06-07" "2006-06-08" "2006-06-09" "2006-06-10"
    [161] "2006-06-11" "2006-06-12" "2006-06-13" "2006-06-14" "2006-06-15"
    [166] "2006-06-16" "2006-06-17" "2006-06-18" "2006-06-19" "2006-06-20"
    [171] "2006-06-21" "2006-06-22" "2006-06-23" "2006-06-24" "2006-06-25"
    [176] "2006-06-26" "2006-06-27" "2006-06-28" "2006-06-29" "2006-06-30"
    [181] "2006-07-01" "2006-07-02" "2006-07-03" "2006-07-04" "2006-07-05"
    [186] "2006-07-06" "2006-07-07" "2006-07-08" "2006-07-09" "2006-07-10"
    [191] "2006-07-11" "2006-07-12" "2006-07-13" "2006-07-14" "2006-07-15"
    [196] "2006-07-16" "2006-07-17" "2006-07-18" "2006-07-19" "2006-07-20"
    [201] "2006-07-21" "2006-07-22" "2006-07-23" "2006-07-24" "2006-07-25"
    [206] "2006-07-26" "2006-07-27" "2006-07-28" "2006-07-29" "2006-07-30"
    [211] "2006-08-01" "2006-08-02" "2006-08-03" "2006-08-04" "2006-08-05"
    [216] "2006-08-06" "2006-08-07" "2006-08-08" "2006-08-09" "2006-08-10"
    [221] "2006-08-11" "2006-08-12" "2006-08-13" "2006-08-14" "2006-08-15"
    [226] "2006-08-16" "2006-08-17" "2006-08-18" "2006-08-19" "2006-08-20"
    [231] "2006-08-21" "2006-08-22" "2006-08-23" "2006-08-24" "2006-08-25"
    [236] "2006-08-26" "2006-08-27" "2006-08-28" "2006-08-29" "2006-08-30"
    [241] "2006-09-01" "2006-09-02" "2006-09-03" "2006-09-04" "2006-09-05"
    [246] "2006-09-06" "2006-09-07" "2006-09-08" "2006-09-09" "2006-09-10"
    [251] "2006-09-11" "2006-09-12" "2006-09-13" "2006-09-14" "2006-09-15"
    [256] "2006-09-16" "2006-09-17" "2006-09-18" "2006-09-19" "2006-09-20"
    [261] "2006-09-21" "2006-09-22" "2006-09-23" "2006-09-24" "2006-09-25"
    [266] "2006-09-26" "2006-09-27" "2006-09-28" "2006-09-29" "2006-09-30"
    [271] "2006-10-01" "2006-10-02" "2006-10-03" "2006-10-04" "2006-10-05"
    [276] "2006-10-06" "2006-10-07" "2006-10-08" "2006-10-09" "2006-10-10"
    [281] "2006-10-11" "2006-10-12" "2006-10-13" "2006-10-14" "2006-10-15"
    [286] "2006-10-16" "2006-10-17" "2006-10-18" "2006-10-19" "2006-10-20"
    [291] "2006-10-21" "2006-10-22" "2006-10-23" "2006-10-24" "2006-10-25"
    [296] "2006-10-26" "2006-10-27" "2006-10-28" "2006-10-29" "2006-10-30"
    [301] "2006-11-01" "2006-11-02" "2006-11-03" "2006-11-04" "2006-11-05"
    [306] "2006-11-06" "2006-11-07" "2006-11-08" "2006-11-09" "2006-11-10"
    [311] "2006-11-11" "2006-11-12" "2006-11-13" "2006-11-14" "2006-11-15"
    [316] "2006-11-16" "2006-11-17" "2006-11-18" "2006-11-19" "2006-11-20"
    [321] "2006-11-21" "2006-11-22" "2006-11-23" "2006-11-24" "2006-11-25"
    [326] "2006-11-26" "2006-11-27" "2006-11-28" "2006-11-29" "2006-11-30"
    [331] "2006-12-01" "2006-12-02" "2006-12-03" "2006-12-04" "2006-12-05"
    [336] "2006-12-06" "2006-12-07" "2006-12-08" "2006-12-09" "2006-12-10"
    [341] "2006-12-11" "2006-12-12" "2006-12-13" "2006-12-14" "2006-12-15"
    [346] "2006-12-16" "2006-12-17" "2006-12-18" "2006-12-19" "2006-12-20"
    [351] "2006-12-21" "2006-12-22" "2006-12-23" "2006-12-24" "2006-12-25"
    [356] "2006-12-26" "2006-12-27" "2006-12-28" "2006-12-29" "2006-12-30"
    [361] "2007-01-01" "2007-01-02" "2007-01-03" "2007-01-04" "2007-01-05"
    [366] "2007-01-06" "2007-01-07" "2007-01-08" "2007-01-09" "2007-01-10"
    [371] "2007-01-11" "2007-01-12" "2007-01-13" "2007-01-14" "2007-01-15"
    [376] "2007-01-16" "2007-01-17" "2007-01-18" "2007-01-19" "2007-01-20"
    [381] "2007-01-21" "2007-01-22" "2007-01-23" "2007-01-24" "2007-01-25"
    [386] "2007-01-26" "2007-01-27" "2007-01-28" "2007-01-29" "2007-01-30"