Time changed when insert data into measurement by used to()

  • when i want to insert data caculated into another measurement, i used code below, and i get a data with timestamp, 2024-07-04 14:02:51
import "math"
import "date"
import "strings"

roundTo = (n, precision) => {
    multiplier = math.pow10(n: precision)
    return math.round(x: n * multiplier) / multiplier
}

endtime = 2024-07-04T06:02:51.054Z
starttime = date.truncate(t: date.add(d: -5m, to: endtime), unit: 1s)
offsecond = duration(v: string(v: date.second(t: endtime)) + "s")

raw = from(bucket: "CS301")
  |> range(start: date.add(d: -10m, to: starttime), stop: endtime)
  |> aggregateWindow(every: 5m, fn: first, offset: 171s)
  |> filter(fn: (r) => r["_measurement"] == "CS105.R-A5100" and r["_field"] == "pi01")
  |> fill(column: "_value", usePrevious: true)
  |> filter(fn: (r) => r["_time"] >= starttime)
  |> limit(n:2, offset: 0)
  |> map(fn: (r) => ({r with _value: roundTo(n: r._value, precision: 2)}))
  |> map(fn: (r) => ({ r with EBRCode: "testE" }))
  |> map(fn: (r) => ({ r with ParameterCode: "testP" }))
  |> keep(columns: ["_measurement", "_field", "_time", "_value", "EBRCode", "ParameterCode"])  
  |> derivative(unit: 1h, nonNegative: true, columns: ["_value"], timeColumn: "_time")
  |> to(bucketID: "b1b276b1702f8526", orgID: "d60f0bfe85e176b3")
  |> yield(name: "custom-name")

  • when i check this piece of data inserted into new measurement, i get a data with timestamp, 2024-07-04 14:03:00

  • when i change range from past 3h to past 12h, the timestamp changes to 2024-07-04 14:04:00

what happed to this piece of data? Could anyone helps me?

this my mistake,i got to this question happed due to aggregatewindow()