text: // Generated by purs version 0.11.6
  "use strict";
  var Control_Apply = require("../Control.Apply");
  var Data_Bounded = require("../Data.Bounded");
  var Data_Enum = require("../Data.Enum");
  var Data_Eq = require("../Data.Eq");
  var Data_EuclideanRing = require("../Data.EuclideanRing");
  var Data_Function = require("../Data.Function");
  var Data_Functor = require("../Data.Functor");
  var Data_Generic = require("../Data.Generic");
  var Data_HeytingAlgebra = require("../Data.HeytingAlgebra");
  var Data_Int = require("../Data.Int");
  var Data_Maybe = require("../Data.Maybe");
  var Data_Newtype = require("../Data.Newtype");
  var Data_Ord = require("../Data.Ord");
  var Data_Ordering = require("../Data.Ordering");
  var Data_Ring = require("../Data.Ring");
  var Data_Semigroup = require("../Data.Semigroup");
  var Data_Semiring = require("../Data.Semiring");
  var Data_Show = require("../Data.Show");
  var Data_Time_Component = require("../Data.Time.Component");
  var Data_Time_Duration = require("../Data.Time.Duration");
  var Data_Tuple = require("../Data.Tuple");
  var Data_Unit = require("../Data.Unit");
  var $$Math = require("../Math");
  var Partial_Unsafe = require("../Partial.Unsafe");
  var Prelude = require("../Prelude");
  var Time = (function () {
      function Time(value0, value1, value2, value3) {
          this.value0 = value0;
          this.value1 = value1;
          this.value2 = value2;
          this.value3 = value3;
      };
      Time.create = function (value0) {
          return function (value1) {
              return function (value2) {
                  return function (value3) {
                      return new Time(value0, value1, value2, value3);
                  };
              };
          };
      };
      return Time;
  })();
  var showTime = new Data_Show.Show(function (v) {
      return "(Time " + (Data_Show.show(Data_Time_Component.showHour)(v.value0) + (" " + (Data_Show.show(Data_Time_Component.showMinute)(v.value1) + (" " + (Data_Show.show(Data_Time_Component.showSecond)(v.value2) + (" " + (Data_Show.show(Data_Time_Component.showMillisecond)(v.value3) + ")")))))));
  });
  var setSecond = function (s) {
      return function (v) {
          return new Time(v.value0, v.value1, s, v.value3);
      };
  };
  var setMinute = function (m) {
      return function (v) {
          return new Time(v.value0, m, v.value2, v.value3);
      };
  };
  var setMillisecond = function (ms) {
      return function (v) {
          return new Time(v.value0, v.value1, v.value2, ms);
      };
  };
  var setHour = function (h) {
      return function (v) {
          return new Time(h, v.value1, v.value2, v.value3);
      };
  };
  var second = function (v) {
      return v.value2;
  };
  var minute = function (v) {
      return v.value1;
  };
  var millisecond = function (v) {
      return v.value3;
  };
  var millisToTime = function (v) {
      var hours = $$Math.floor(v / 3600000.0);
      var minutes = $$Math.floor((v - hours * 3600000.0) / 60000.0);
      var seconds = $$Math.floor((v - (hours * 3600000.0 + minutes * 60000.0)) / 1000.0);
      var milliseconds = v - (hours * 3600000.0 + minutes * 60000.0 + seconds * 1000.0);
      return Data_Maybe.fromJust()(Control_Apply.apply(Data_Maybe.applyMaybe)(Control_Apply.apply(Data_Maybe.applyMaybe)(Control_Apply.apply(Data_Maybe.applyMaybe)(Data_Functor.map(Data_Maybe.functorMaybe)(Time.create)(Data_Enum.toEnum(Data_Time_Component.boundedEnumHour)(Data_Int.floor(hours))))(Data_Enum.toEnum(Data_Time_Component.boundedEnumMinute)(Data_Int.floor(minutes))))(Data_Enum.toEnum(Data_Time_Component.boundedEnumSecond)(Data_Int.floor(seconds))))(Data_Enum.toEnum(Data_Time_Component.boundedEnumMillisecond)(Data_Int.floor(milliseconds))));
  };
  var hour = function (v) {
      return v.value0;
  };
  var timeToMillis = function (t) {
      return Data_Time_Duration.Milliseconds(3600000.0 * Data_Int.toNumber(Data_Enum.fromEnum(Data_Time_Component.boundedEnumHour)(hour(t))) + 60000.0 * Data_Int.toNumber(Data_Enum.fromEnum(Data_Time_Component.boundedEnumMinute)(minute(t))) + 1000.0 * Data_Int.toNumber(Data_Enum.fromEnum(Data_Time_Component.boundedEnumSecond)(second(t))) + Data_Int.toNumber(Data_Enum.fromEnum(Data_Time_Component.boundedEnumMillisecond)(millisecond(t))));
  };
  var genericTime = new Data_Generic.Generic(function (v) {
      if (v instanceof Data_Generic.SProd && (v.value0 === "Data.Time.Time" && v.value1.length === 4)) {
          return Control_Apply.apply(Data_Maybe.applyMaybe)(Control_Apply.apply(Data_Maybe.applyMaybe)(Control_Apply.apply(Data_Maybe.applyMaybe)(Control_Apply.apply(Data_Maybe.applyMaybe)(new Data_Maybe.Just(Time.create))(Data_Generic.fromSpine(Data_Time_Component.genericHour)(v["value1"][0](Data_Unit.unit))))(Data_Generic.fromSpine(Data_Time_Component.genericMinute)(v["value1"][1](Data_Unit.unit))))(Data_Generic.fromSpine(Data_Time_Component.genericSecond)(v["value1"][2](Data_Unit.unit))))(Data_Generic.fromSpine(Data_Time_Component.genericMillisecond)(v["value1"][3](Data_Unit.unit)));
      };
      return Data_Maybe.Nothing.value;
  }, function ($dollarq) {
      return new Data_Generic.SigProd("Data.Time.Time", [ {
          sigConstructor: "Data.Time.Time", 
          sigValues: [ function ($dollarq1) {
              return Data_Generic.toSignature(Data_Time_Component.genericHour)(Data_Generic.anyProxy);
          }, function ($dollarq1) {
              return Data_Generic.toSignature(Data_Time_Component.genericMinute)(Data_Generic.anyProxy);
          }, function ($dollarq1) {
              return Data_Generic.toSignature(Data_Time_Component.genericSecond)(Data_Generic.anyProxy);
          }, function ($dollarq1) {
              return Data_Generic.toSignature(Data_Time_Component.genericMillisecond)(Data_Generic.anyProxy);
          } ]
      } ]);
  }, function (v) {
      return new Data_Generic.SProd("Data.Time.Time", [ function ($dollarq) {
          return Data_Generic.toSpine(Data_Time_Component.genericHour)(v.value0);
      }, function ($dollarq) {
          return Data_Generic.toSpine(Data_Time_Component.genericMinute)(v.value1);
      }, function ($dollarq) {
          return Data_Generic.toSpine(Data_Time_Component.genericSecond)(v.value2);
      }, function ($dollarq) {
          return Data_Generic.toSpine(Data_Time_Component.genericMillisecond)(v.value3);
      } ]);
  });
  var eqTime = new Data_Eq.Eq(function (x) {
      return function (y) {
          return Data_Eq.eq(Data_Time_Component.eqHour)(x.value0)(y.value0) && Data_Eq.eq(Data_Time_Component.eqMinute)(x.value1)(y.value1) && Data_Eq.eq(Data_Time_Component.eqSecond)(x.value2)(y.value2) && Data_Eq.eq(Data_Time_Component.eqMillisecond)(x.value3)(y.value3);
      };
  });
  var ordTime = new Data_Ord.Ord(function () {
      return eqTime;
  }, function (x) {
      return function (y) {
          var v = Data_Ord.compare(Data_Time_Component.ordHour)(x.value0)(y.value0);
          if (v instanceof Data_Ordering.LT) {
              return Data_Ordering.LT.value;
          };
          if (v instanceof Data_Ordering.GT) {
              return Data_Ordering.GT.value;
          };
          var v1 = Data_Ord.compare(Data_Time_Component.ordMinute)(x.value1)(y.value1);
          if (v1 instanceof Data_Ordering.LT) {
              return Data_Ordering.LT.value;
          };
          if (v1 instanceof Data_Ordering.GT) {
              return Data_Ordering.GT.value;
          };
          var v2 = Data_Ord.compare(Data_Time_Component.ordSecond)(x.value2)(y.value2);
          if (v2 instanceof Data_Ordering.LT) {
              return Data_Ordering.LT.value;
          };
          if (v2 instanceof Data_Ordering.GT) {
              return Data_Ordering.GT.value;
          };
          return Data_Ord.compare(Data_Time_Component.ordMillisecond)(x.value3)(y.value3);
      };
  });
  var diff = function (dictDuration) {
      return function (t1) {
          return function (t2) {
              return Data_Time_Duration.toDuration(dictDuration)(Data_Ring.sub(Data_Time_Duration.ringMilliseconds)(timeToMillis(t1))(timeToMillis(t2)));
          };
      };
  };
  var boundedTime = new Data_Bounded.Bounded(function () {
      return ordTime;
  }, new Time(Data_Bounded.bottom(Data_Time_Component.boundedHour), Data_Bounded.bottom(Data_Time_Component.boundedMinute), Data_Bounded.bottom(Data_Time_Component.boundedSecond), Data_Bounded.bottom(Data_Time_Component.boundedMillisecond)), new Time(Data_Bounded.top(Data_Time_Component.boundedHour), Data_Bounded.top(Data_Time_Component.boundedMinute), Data_Bounded.top(Data_Time_Component.boundedSecond), Data_Bounded.top(Data_Time_Component.boundedMillisecond)));
  var maxTime = timeToMillis(Data_Bounded.top(boundedTime));
  var adjust = function (dictDuration) {
      return function (d) {
          return function (t) {
              var tLength = timeToMillis(t);
              var d$prime = Data_Time_Duration.fromDuration(dictDuration)(d);
              var wholeDays = Data_Time_Duration.Days($$Math.floor(Data_Newtype.unwrap(Data_Time_Duration.newtypeMilliseconds)(d$prime) / 8.64e7));
              var msAdjust = Data_Ring.sub(Data_Time_Duration.ringMilliseconds)(d$prime)(Data_Time_Duration.fromDuration(Data_Time_Duration.durationDays)(wholeDays));
              var msAdjusted = Data_Semiring.add(Data_Time_Duration.semiringMilliseconds)(tLength)(msAdjust);
              var wrap = (function () {
                  var $134 = Data_Ord.greaterThan(Data_Time_Duration.ordMilliseconds)(msAdjusted)(maxTime);
                  if ($134) {
                      return 1.0;
                  };
                  var $135 = Data_Ord.lessThan(Data_Time_Duration.ordMilliseconds)(msAdjusted)(Data_Ring.negate(Data_Time_Duration.ringMilliseconds)(maxTime));
                  if ($135) {
                      return -1.0;
                  };
                  return 0.0;
              })();
              return new Data_Tuple.Tuple(Data_Semiring.add(Data_Time_Duration.semiringDays)(wholeDays)(wrap), millisToTime(Data_Ring.sub(Data_Time_Duration.ringMilliseconds)(msAdjusted)(8.64e7 * wrap)));
          };
      };
  };
  module.exports = {
      Time: Time, 
      adjust: adjust, 
      diff: diff, 
      hour: hour, 
      millisecond: millisecond, 
      minute: minute, 
      second: second, 
      setHour: setHour, 
      setMillisecond: setMillisecond, 
      setMinute: setMinute, 
      setSecond: setSecond, 
      eqTime: eqTime, 
      ordTime: ordTime, 
      genericTime: genericTime, 
      boundedTime: boundedTime, 
      showTime: showTime
  };
  