Pinkstack/roblox-luau-corpus-text huggingface dataset:
--[[ Reference extension ]]

--

do
	local ReferenceTypes = {
		Character = {},
		CharacterPart = {}
	}

	local References = {} 
	local Objects = {}

	for i,v in pairs(ReferenceTypes) do
		References[i] = {}
		Objects[i] = {}
	end
	
	function Network:AddReference(key, refType, ...)
		local refInfo = ReferenceTypes[refType]
		assert(refInfo, "Invalid Reference Type")
		
		local refData = {
			Type = refType,
			Reference = key,
			Objects = {...},
			Aliases = {}
		}
		
		References[refType][refData.Reference] = refData
		
		local last = Objects[refType]
		for _,obj in ipairs(refData.Objects) do
			local list = last[obj] or {}
			last[obj] = list
			last = list
		end
		
		last.__Data = refData
	end

	function Network:AddReferenceAlias(key, refType, ...)
		local refInfo = ReferenceTypes[refType]
		assert(refInfo, "Invalid Reference Type")
		
		local refData = References[refType][key]
		if not refData then
			warn("Tried to add an alias to a non-existing reference")
			return
		end
		
		local objects = {...}
		refData.Aliases[#refData.Aliases + 1] = objects
		
		local last = Objects[refType]
		for _,obj in ipairs(objects) do
			local list = last[obj] or {}
			last[obj] = list
			last = list
		end
		
		last.__Data = refData
	end

	function Network:RemoveReference(key, refType)
		local refInfo = ReferenceTypes[refType]
		assert(refInfo, "Invalid Reference Type")
		
		local refData = References[refType][key]
		if not refData then
			warn("Tried to remove a non-existing reference")
			return
		end
		
		References[refType][refData.Reference] = nil
		
		local function rem(parent, objects, index)
			if index <= #objects then
				local key = objects[index]
				local child = parent[key]
				
				rem(child, objects, index + 1)
				
				if next(child) == nil then
					parent[key] = nil
				end
			elseif parent.__Data == refData then
				parent.__Data = nil
			end
		end
		
		local objects = Objects[refData.Type]
		rem(objects, refData.Objects, 1)
		
		for i,alias in ipairs(refData.Aliases) do
			rem(objects, alias, 1)
		end
	end

	function Network:GetObject(ref, refType)
		assert(ReferenceTypes[refType], "Invalid Reference Type")
		
		local refData = References[refType][ref]
		if not refData then
			return nil
		end
		
		return unpack(refData.Objects)
	end

	function Network:GetReference(...)
		local objects = {...}
		
		local refType = table.remove(objects)
		assert(ReferenceTypes[refType], "Invalid Reference Type")
		
		local last = Objects[refType]
		for i,v in ipairs(objects) do
			last = last[v]
			
			if not last then
				break
			end
		end
		
		local refData = last and last.__Data
		return refData and refData.Reference or nil
	end
end
-- Explicit dependencies are dependencies that are are explicitly listed.
-- These dependencies are available to this package and ANY dependent packages below


function PackageInfoUtils.fillExplicitPackageDependencySet(explicitDependencySet, packageFolder, packageInfoMap)
	assert(type(explicitDependencySet) == "table", "Bad explicitDependencySet")
	assert(typeof(packageFolder) == "Instance", "Bad packageFolder")
	assert(type(packageInfoMap) == "table", "Bad packageInfoMap")

	for _, item in pairs(packageFolder:GetChildren()) do
		if item:IsA("Folder") and item.Name == ScriptInfoUtils.DEPENDENCY_FOLDER_NAME then
			for _, packageInfo in pairs(PackageInfoUtils.getPackageInfoListFromDependencyFolder(item, packageInfoMap)) do
				explicitDependencySet[packageInfo] = true
			end
		end
	end
end

return PackageInfoUtils
--------LEFT DOOR --------



game.Workspace.doorleft.l12.BrickColor = BrickColor.new(game.Workspace.Lighting.defaultlights.Value)

game.Workspace.doorleft.l23.BrickColor = BrickColor.new(game.Workspace.Lighting.defaultlights.Value)
game.Workspace.doorleft.l61.BrickColor = BrickColor.new(game.Workspace.Lighting.defaultlights.Value)
game.Workspace.doorleft.l42.BrickColor = BrickColor.new(game.Workspace.Lighting.defaultlights.Value)
game.Workspace.doorleft.l72.BrickColor = BrickColor.new(game.Workspace.Lighting.defaultlights.Value)
game.Workspace.doorleft.l53.BrickColor = BrickColor.new(game.Workspace.Lighting.defaultlights.Value)
game.Workspace.doorleft.l71.BrickColor = BrickColor.new(game.Workspace.Lighting.defaultlights.Value)
game.Workspace.doorleft.l31.BrickColor = BrickColor.new(game.Workspace.Lighting.defaultlights.Value)

game.Workspace.doorleft.l11.BrickColor = BrickColor.new(game.Workspace.Lighting.defaultlights.Value)
game.Workspace.doorleft.l21.BrickColor = BrickColor.new(game.Workspace.Lighting.defaultlights.Value)
game.Workspace.doorleft.l22.BrickColor = BrickColor.new(game.Workspace.Lighting.defaultlights.Value)
game.Workspace.doorleft.l32.BrickColor = BrickColor.new(game.Workspace.Lighting.defaultlights.Value)
game.Workspace.doorleft.l33.BrickColor = BrickColor.new(game.Workspace.Lighting.defaultlights.Value)
game.Workspace.doorleft.l43.BrickColor = BrickColor.new(game.Workspace.Lighting.defaultlights.Value)
game.Workspace.doorleft.l51.BrickColor = BrickColor.new(game.Workspace.Lighting.defaultlights.Value)
game.Workspace.doorleft.l41.BrickColor = BrickColor.new(game.Workspace.Lighting.defaultlights.Value)
game.Workspace.doorleft.l73.BrickColor = BrickColor.new(game.Workspace.Lighting.defaultlights.Value)
game.Workspace.doorleft.l52.BrickColor = BrickColor.new(game.Workspace.Lighting.defaultlights.Value)
game.Workspace.doorleft.l63.BrickColor = BrickColor.new(game.Workspace.Lighting.defaultlights.Value)
game.Workspace.doorleft.l62.BrickColor = BrickColor.new(game.Workspace.Lighting.defaultlights.Value)
game.Workspace.doorleft.l13.BrickColor = BrickColor.new(game.Workspace.Lighting.defaultlights.Value)

game.Workspace.doorleft.pillar.BrickColor = BrickColor.new(game.Workspace.Lighting.defaultlights.Value)
-- How to install
-- Put the "[FE+] Pedals" script into the Plugins folder
-- Move the "BP","CP" and "GP" groups to fit the interior, and put them in the Misc group
-- Copy and paste the following into MiscWeld under initialize.



MakeWeld(misc.BP.SS,car.DriveSeat,"Motor",.1)
ModelWeld(misc.BP.Parts,misc.BP.SS)
MakeWeld(misc.GP.SS,car.DriveSeat,"Motor",.1)
ModelWeld(misc.GP.Parts,misc.GP.SS)
MakeWeld(misc.CP.SS,car.DriveSeat,"Motor",.1)
ModelWeld(misc.CP.Parts,misc.CP.SS)
--[[Weight and CG]]


	Tune.Weight			= 2200		-- Total weight (in pounds)
	Tune.WeightBSize	= {			-- Size of weight brick (dimmensions in studs ; larger = more stable)
	 --[[Width]]		8		,
	 --[[Height]]		4.5		,
	 --[[Length]]		16		}
	Tune.WeightDist		= 50		-- Weight distribution (0 - on rear wheels, 100 - on front wheels, can be <0 or >100)
	Tune.CGHeight		= .8		-- Center of gravity height (studs relative to median of all wheels)
	Tune.WBVisible		= false		-- Makes the weight brick visible
	
	--Unsprung Weight
	Tune.FWheelDensity	= .1		-- Front Wheel Density
	Tune.RWheelDensity	= .1		-- Rear Wheel Density
	Tune.FWLgcyDensity	= 1			-- Front Wheel Density [PGS OFF]
	Tune.RWLgcyDensity	= 1			-- Rear Wheel Density [PGS OFF]
	
	Tune.AxleSize		= 2			-- Size of structural members (larger = more stable/carry more weight)
	Tune.AxleDensity	= .1		-- Density of structural members
--// Module LoadOrder List; Core modules need to be loaded in a specific order; If you create new "Core" modules make sure you add them here or they won't load


local LoadingOrder = {
	--// Nearly all modules rely on these to function
	"Logs";
	"Variables";
	"Functions";
a
	--// Core functionality
	"Core";
	"Remote";
	"Process";

	--// Misc
	"Admin";
	"HTTP";
	"Anti";
	"Commands";
}
--[=[
	This function returns a table with the values of the passed dictionary.
	
	```lua
	local Dictionary = {
		A = 1,
		B = 2,
		C = 3,
	}
	
	print(TableKit.Values(Dictionary)) -- prints {1, 2, 3}
	```

	@within TableKit
	@param dictionary table
	@return table
]=]


function TableKit.Values<T>(dictionary: { [unknown]: T }): { T }
	local valueArray = {}

	for _, value in dictionary do
		table.insert(valueArray, value)
	end

	return valueArray
end
--[[
		___      _______                _     
	   / _ |____/ ___/ /  ___ ____ ___ (_)__ 
	  / __ /___/ /__/ _ \/ _ `(_-<(_-</ (_-<
	 /_/ |_|   \___/_//_/\_,_/___/___/_/___/
 						SecondLogic @ Inspare
]]


local FE = workspace.FilteringEnabled
local car = script.Parent.Car.Value
local handler = car:WaitForChild("AC6_FE_Sounds")
local _Tune = require(car["A-Chassis Tune"])
local on = 0
local throt=0
local redline=0

script:WaitForChild("Rev")

for _,v in ipairs(car.DriveSeat:GetChildren()) do
	for _,a in ipairs(script:GetChildren()) do
		if v.Name==a.Name then v:Stop() wait() v:Destroy() end
	end
end

handler:FireServer("newSound","Rev",car.DriveSeat,script.Rev.SoundId,0,script.Rev.Volume,true)
handler:FireServer("playSound","Rev")
car.DriveSeat:WaitForChild("Rev")

game:GetService("RunService").Heartbeat:Connect(function() -- to-do: linear interpolate on all clients at 10/s to avoid bogging down network
	local _RPM = script.Parent.Values.RPM.Value
	
	if script.Parent.Values.Throttle.Value <= _Tune.IdleThrottle/100 then
		throt = math.max(.3,throt-.2)	
	else
		throt = math.min(1,throt+.1)	
	end	
	if script.Parent.Values.RPM.Value > _Tune.Redline-_Tune.RevBounce/4 and script.Parent.Values.Throttle.Value > _Tune.IdleThrottle/100 then
		redline=.5
	else
		redline=1
	end
	if not script.Parent.IsOn.Value then on=math.max(on-.015,0) else on=1 end
	local Pitch = math.max((((script.Rev.SetPitch.Value + script.Rev.SetRev.Value*_RPM/_Tune.Redline))*on^2),script.Rev.SetPitch.Value)
	if FE then
		handler:FireServer("updateSound","Rev",script.Rev.SoundId,Pitch,script.Rev.Volume)
	else
		car.DriveSeat.Rev.Pitch = Pitch
	end
end)
-- VisualComponents by Travis, modified for native visuals. 



local module = {}

module.panels = {}

local MapConstant = 40000
local VideoControl = require(script.VideoControl.Value)

local function mapScreen(center,screen)
	local dif = Instance.new("Attachment",center)
	dif.WorldPosition = screen.Position

	for i,v in pairs(screen.VisualScreen.Main:GetChildren()) do
		if v:IsA("ImageLabel") then
			v.Position = UDim2.new(0.5, dif.Position.X * MapConstant, 0.5, (dif.Position.Y - dif.Position.Z) * MapConstant )
		end
	end
	for i,v in pairs(screen.VisualScreen.SpriteVisual:GetChildren()) do
		if v:IsA("ImageLabel") then
			v.Position = UDim2.new(0.5, dif.Position.X * MapConstant, 0.5, (dif.Position.Y - dif.Position.Z) * MapConstant )
		end
	end


	screen.VisualScreen.CanvasSize = Vector2.new((screen.Size.X*MapConstant),(screen.Size.Y*MapConstant))
	dif:Destroy()
end

function module.Start(screensFolder)
	local center = screensFolder.CenterPart
	if screensFolder:FindFirstChild("Panels") then
		for i,v in pairs(screensFolder.Panels:GetChildren()) do
			local cloneFrame = script.Main:Clone()
			local cloneFrame1 = script.SpriteVisual:Clone()
			cloneFrame.Parent = v.VisualScreen
			cloneFrame1.Parent = v.VisualScreen
			mapScreen(center,v)
			table.insert(module.panels,v)
			v.Debug:Destroy()
		end
	end
	VideoControl.SpriteStart()
end


return module
--[=[
	Utility to build a localization table from json, intended to be used with rojo. Can also handle Rojo json
	objects turned into tables!

	@class JsonToLocalizationTable
]=]



local LocalizationService = game:GetService("LocalizationService")
local HttpService = game:GetService("HttpService")
local RunService = game:GetService("RunService")

local JsonToLocalizationTable = {}

local LOCALIZATION_TABLE_NAME = "GeneratedJSONTable"
-- ================================================================================
-- LOCAL FUNCTIONS
-- ================================================================================


local function setModelAnchored(parent, anchored)
	for _, child in ipairs(parent:GetChildren()) do
		if (child:IsA("BasePart")) or (child:IsA("MeshPart")) then
			child.Anchored = anchored
		end
		setModelAnchored(child, anchored)
	end
end -- setModelAnchored()

local function setModelCanCollide(parent, canCollide)
	for _, child in ipairs(parent:GetChildren()) do
		if (child:IsA("BasePart")) or (child:IsA("MeshPart")) then
			child.CanCollide = canCollide
		end
		setModelAnchored(child, canCollide)
	end
end -- setModelCanCollide()

local function setModelTransparency(parent, transparency)
	for _, child in ipairs(parent:GetChildren()) do
		if (child:IsA("BasePart")) or (child:IsA("MeshPart")) then
			child.Transparency = transparency
		end
		setModelTransparency(child, transparency)
	end
end -- setModelTransparency()

local function removeLimbsAndThings(character)
	for _, child in ipairs(character:GetChildren()) do
		removeLimbsAndThings(child)
		if (not child:IsA("Humanoid")) and (not child:IsA("Motor6D")) 
			and (child.Name ~= "Head") and (child.Name ~= "UpperTorso") then
				child:Destroy()
		end
	end
end -- removeLimbsAndThings()

local function insertModelIntoCharacter(character, model)
	for _, child in ipairs(model:GetChildren()) do
		child.Parent = character
		insertModelIntoCharacter(child, child)
	end
end -- insertModelIntoCharacter()

local function setCollisionGroup(parent, group)
	for _,part in pairs(parent:GetChildren()) do
		if (part:IsA("BasePart") or (part:IsA("MeshPart"))) then
			PhysicsService:SetPartCollisionGroup(part, group)
		end
	end
end -- SetCollisionGroup()
--[[Engine]]


	--Torque Curve
	Tune.Horsepower		= 75
	Tune.IdleRPM		= 500
	Tune.PeakRPM		= 5600
	Tune.Redline		= 6300
	Tune.EqPoint		= 6300
	Tune.PeakSharpness	= 2.2
	Tune.CurveMult		= 0.01
	
	--Incline Compensation
	Tune.InclineComp	= 1.35			-- Torque compensation multiplier for inclines (applies gradient from 0-90 degrees)
	
	--Misc
	Tune.RevAccel		= 0		-- RPM acceleration when clutch is off
	Tune.RevDecay		= 75		-- RPM decay when clutch is off
	Tune.RevBounce		= 500		-- RPM kickback from redline
	Tune.IdleThrottle	= 0			-- Percent throttle at idle
	Tune.ClutchTol		= 450		-- Clutch engagement threshold (higher = faster response)
--[[ Local Variables ]]

--
local MasterControl = {}

local Players = game:GetService('Players')
local RunService = game:GetService('RunService')

while not Players.LocalPlayer do
	wait()
end
local LocalPlayer = Players.LocalPlayer
local CachedHumanoid = nil
local RenderSteppedCon = nil
local SeatedCn = nil
local moveFunc = LocalPlayer.Move

local isJumping = false
local isSeated = false
local myVehicleSeat = nil
local moveValue = Vector3.new(0,0,0)
-- functions



function stopAllAnimations()
	local oldAnim = currentAnim

	-- return to idle if finishing an emote
	if (emoteNames[oldAnim] ~= nil and emoteNames[oldAnim] == false) then
		oldAnim = "idle"
	end

	currentAnim = ""
	if (currentAnimKeyframeHandler ~= nil) then
		currentAnimKeyframeHandler:Disconnect()
	end

	if (oldAnimTrack ~= nil) then
		oldAnimTrack:Stop()
		oldAnimTrack:Destroy()
		oldAnimTrack = nil
	end
	if (currentAnimTrack ~= nil) then
		currentAnimTrack:Stop()
		currentAnimTrack:Destroy()
		currentAnimTrack = nil
	end
	return oldAnim
end

function setAnimationSpeed(speed)
	if speed ~= currentAnimSpeed then
		currentAnimSpeed = speed
		currentAnimTrack:AdjustSpeed(currentAnimSpeed)
	end
end

function keyFrameReachedFunc(frameName)
	if (frameName == "End") then
--//ENGINE//--


Horsepower = 430  --{This is how much power your engine block makes ALONE, this does not represent to total horsepower output [IF you have a turbo/SC]}
EngineDisplacement = 3000 --{Engine size in CC's}
EngineType =  "Diesel" --{Petrol, Diesel, Electric]
EngineLocation = "Front" --{Front, Mid, Rear}
ForcedInduction = "Single" --{Natural, Single, Twin, Supercharger} 
InductionPartSize = 1.5 --{0-5, 1 being small, 5 being large (Decimals accepted, e.g 2.64 turbo size, this is the size of the turbo}
ElectronicallyLimited = false --{Electronically Limit the top speed of your vehicle}
LimitSpeedValue = 100 --{Limits top speed of the vehicle [In MPH]}
--------LEFT DOOR --------


game.Workspace.doorleft.l11.BrickColor = BrickColor.new(133)
game.Workspace.doorleft.l12.BrickColor = BrickColor.new(133)
game.Workspace.doorleft.l13.BrickColor = BrickColor.new(133)
game.Workspace.doorleft.l41.BrickColor = BrickColor.new(133)
game.Workspace.doorleft.l42.BrickColor = BrickColor.new(133)
game.Workspace.doorleft.l43.BrickColor = BrickColor.new(133)
game.Workspace.doorleft.l71.BrickColor = BrickColor.new(133)
game.Workspace.doorleft.l72.BrickColor = BrickColor.new(133)
game.Workspace.doorleft.l73.BrickColor = BrickColor.new(133)

game.Workspace.doorleft.l21.BrickColor = BrickColor.new(106)
game.Workspace.doorleft.l22.BrickColor = BrickColor.new(106)
game.Workspace.doorleft.l23.BrickColor = BrickColor.new(106)
game.Workspace.doorleft.l51.BrickColor = BrickColor.new(106)
game.Workspace.doorleft.l52.BrickColor = BrickColor.new(106)
game.Workspace.doorleft.l53.BrickColor = BrickColor.new(106)

game.Workspace.doorleft.l31.BrickColor = BrickColor.new(21)
game.Workspace.doorleft.l32.BrickColor = BrickColor.new(21)
game.Workspace.doorleft.l33.BrickColor = BrickColor.new(21)
game.Workspace.doorleft.l61.BrickColor = BrickColor.new(21)
game.Workspace.doorleft.l62.BrickColor = BrickColor.new(21)
game.Workspace.doorleft.l63.BrickColor = BrickColor.new(21)

game.Workspace.doorleft.pillar.BrickColor = BrickColor.new(106)
--Function of the repair button


repair.MouseButton1Down:connect(function()
	if repairtwo == true then
		repairtwo = false
		local ff = Instance.new ("ForceField")
		ff.Parent = sp
		sp.Temporary:ClearAllChildren()
		menudisappear()
		disappearall()
		click.MaxActivationDistance = 10
		coverup()
		wait(1)
		ready = true
		ff:Destroy()
		
		for _,force in pairs(sp:GetChildren()) do
				if force:IsA("ForceField") then
					force:Destroy()
				end
		end
		
		script.Fixer.Disabled = true
		wait(5)
		repairtwo = true
	end
	
end)
--Main


local CacheManager: any = {}
CacheManager.__index = CacheManager

function CacheManager.new()
    local self = setmetatable({}, CacheManager)
    self.Cache = {}
    self.CacheLimit = math.huge
    self.Locked = false
    self.CacheParent = workspace

    return self
end

function CacheManager:SetCacheLimit(limit: number)
    self.CacheLimit = math.max(limit, 1)

    for _, cacheEntry: {[string]: any} in pairs(self.Cache) do
        local cacheToPurge: number = math.max(0, self.CacheLimit - #cacheEntry.Cache)

        if cacheToPurge > 0 then
            for _ = 1, cacheToPurge do
                cacheEntry.Cache[#cacheEntry.Cache]:Destroy()
                cacheEntry.Cache[#cacheEntry.Cache] = nil
            end
        end
    end
end

function CacheManager:Return(id: string, obj: Instance)
    if self.Locked then
        obj:Destroy()
        return    
    end

    if self.Cache[id] then
        if #self.Cache[id].Cache < self.CacheLimit then
            if obj:IsA("BasePart") then
                obj.Anchored = true
            elseif obj:IsA("Model") and obj.PrimaryPart then
                obj.PrimaryPart.Anchored = true
            end

            --? Maybe i should use bulkmoveto instead of this
            if obj:IsA("PVInstance") then
                obj:PivotTo(farawayCFrame)
            end
        
            table.insert(self.Cache[id].Cache, obj)
        else
            obj:Destroy()
        end
    end
end

function CacheManager:Take(id: string)
    if self.Locked then return end 

    if self.Cache[id] then
        local storedNum: number = #self.Cache[id].Cache

        if storedNum == 0 then
            local obj: Instance = self.Cache[id].Original:Clone()
            obj.Parent = self.CacheParent

            return obj
        else
            local obj: Instance = self.Cache[id].Cache[storedNum]
            
            self.Cache[id].Cache[storedNum] = nil

            if obj:IsA("BasePart") then
                obj.Anchored = false
            elseif obj:IsA("Model") and obj.PrimaryPart then
                obj.PrimaryPart.Anchored = false
            end

            return obj
        end
    end
end

function CacheManager:Register(id: string, obj: Instance)
    if self.Locked then 
        obj:Destroy()
        return 
    end

    if not self.Cache[id] then
        self.Cache[id] = {
            Cache = {},
            Original = obj
        }
    end
end

function CacheManager:Destroy(): ()
    self.Locked = true
    
    local _, cacheEntry: {[string]: Instance | {Instance}} = next(self.Cache)

    repeat
        cacheEntry.Original:Destroy()

        repeat
            cacheEntry.Cache[#cacheEntry.Cache]:Destroy()
            cacheEntry.Cache[#cacheEntry.Cache] = nil
        until #cacheEntry.Cache == 0

        _, cacheEntry = next(self.Cache)
    until cacheEntry == nil

    self.Cache = nil
    self = nil
end

return CacheManager
-------------------------------------------


local weld2 = Instance.new("Weld")
weld2.Part0 = torso
weld2.Parent = torso
weld2.Part1 = arms[2]
weld2.C1 = CFrame.new(0.5,0.495,1.25) * CFrame.fromEulerAnglesXYZ(math.rad(90),0,0)
arms[2].Name = "RDave"
arms[2].CanCollide = true
welds[2] = weld2
--[[Brakes]]


	Tune.ABSEnabled		= true		-- Implements ABS
	Tune.ABSThreshold	= 20		-- Slip speed allowed before ABS starts working (in SPS) 

	Tune.FBrakeForce	= 3000		-- Front brake force
	Tune.RBrakeForce	= 2500		-- Rear brake force
	Tune.PBrakeForce	= 100000		-- Handbrake force
	
	Tune.FLgcyBForce	= 15000		-- Front brake force [PGS OFF]
	Tune.RLgcyBForce	= 10000		-- Rear brake force [PGS OFF]
	Tune.LgcyPBForce	= 25000		-- Handbrake force [PGS OFF]
--[[
	-- Time functions
	-- @author Narrev
	
	This module can be called like so:
	
	timeModule = require(331894616) 	
	
	timeModule.Date() 			--> returns (year, month, days) @ timestamp tick()
	timeModule.Date(seconds) 	--> returns (year, month, days) @ seconds after epoch time
	
	timeModule.Time()			--> returns (hours, minutes, seconds) @ timestamp tick()
	timeModule.Time(seconds)	--> returns (hours, minutes, seconds) @ seconds after epoch time
	
--]]



local floor, ceil = math.floor, math.ceil

local function isLeapYear(year)
    return year % 4 == 0 and (year % 25 ~= 0 or year % 16 == 0)
end

local function GetLeaps(year)
	return floor(year/4) - floor(year/100) + floor(year/400)
end

local function CountDays(year)
	return 365*year + GetLeaps(year)
end

local function CountDays2(year)
	return 365*year + GetLeaps(year - 1)	
end

local function overflow(array, seed)
	for i = 1, #array do
		if seed - array[i] <= 0 then
			return i, seed
		end
		seed = seed - array[i]
	end
end

local function GetYMDFromSeconds(seconds)
	local seconds = seconds or tick()
    local days = ceil((seconds + 1) / 86400) + CountDays(1970)
    
    local _400Years = 400*floor(days / CountDays(400))
    local _100Years = 100*floor(days % CountDays(400) / CountDays(100))
    local _4Years = 4*floor(days % CountDays(400) % CountDays(100) / CountDays(4))
    
    local _1Years, month
    _1Years, days = overflow({366,365,365,365}, days - CountDays2(_4Years + _100Years + _400Years))
	_1Years	= _1Years - 1
    
    local year = _1Years + _4Years + _100Years + _400Years
    month, days = overflow({31,isLeapYear(year) and 29 or 28,31,30,31,30,31,31,30,31,30,31}, days)
        
	return year, month, days
end

local function GetTimeFromSeconds(seconds)
	local hours	= floor(seconds / 3600 % 24)
	local minutes	= floor(seconds / 60 % 60)
	local seconds	= floor(seconds % 60)
	
	return hours, minutes, seconds
end

return {Date = GetYMDFromSeconds, Time = GetTimeFromSeconds}
--[=[
	Observes a link value that is not nil.

	@param linkName string
	@param parent Instance
	@return Brio<Instance>
]=]


function RxLinkUtils.observeLinkValueBrio(linkName, parent)
	assert(type(linkName) == "string", "linkName should be 'string'")
	assert(typeof(parent) == "Instance", "parent should be 'Instance'")

	return RxInstanceUtils.observeChildrenOfNameBrio(parent, "ObjectValue", linkName)
		:Pipe({
			RxBrioUtils.flatMapBrio(function(instance)
				return RxInstanceUtils.observePropertyBrio(instance, "Value", function(value)
					return value ~= nil
				end)
			end)
		})
end