1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146
|
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Library General Public
# License as published by the Free Software Foundation; either
# version 2 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Library General Public License for more details.
#
# You should have received a copy of the GNU Library General
# Public License along with this library; if not, write to the
# Free Foundation, Inc., 59 Temple Place, Suite 330, Boston,
# MA 02111-1307 USA
# Copyrights (C)
# for this R-port:
# 1999 - Diethelm Wuertz, GPL
# 2007 - Rmetrics Foundation, GPL
# Diethelm Wuertz <wuertz@phys.ethz.ch>
# www.rmetrics.org
# for the code accessed (or partly included) from other R-ports:
# see R's copyright and license files
# for the code accessed (or partly included) from contributed R-ports
# and other sources
# see Rmetrics's copyright file
################################################################################
# FUNCTION: DESCRIPTION:
# rulesFinCenter Returns DST rules for a financial center
################################################################################
rulesFinCenter <-
function(FinCenter = myFinCenter)
{
# A function implemented by Diethelm Wuertz
# Description:
# Show the day light saving rules for a financial center
# Arguments:
# FinCenter - a character string with the the location of the
# financial center named as "continent/city".
# FUNCTION:
# Check:
if (FinCenter == "GMT" | FinCenter == "")
stop("There are no DST rules for GMT FinCenter!")
# Set Timezone to GMT:
myTZ = Sys.getenv("TZ")
Sys.setenv(TZ = "GMT")
if (FinCenter == "") FinCenter = "GMT"
TZ <- Sys.getenv("TZ")
if(TZ[[1]] != "GMT") {
Sys.setenv(TZ = "GMT")
on.exit(Sys.setenv(TZ = TZ))
}
# Internal Function for Conversion from Ical Tables:
# if (FALSE) {
# rulesFinCenter2 =
# function(FinCenter = myFinCenter) {
# # A function implemented by Diethelm Wuertz
# # Description:
# # Show the day light saving rules for a financial center
# # Arguments:
# # FinCenter - a character string with the the location of the
# # financial center named as "continent/city".
# # Value:
# # Returns a printed list of DST rules.
# # Example:
# # > rulesFinCenter("Zurich")
# # ruleChanges offSet
# # 1 1894-05-31 23:30:16 3600
# # 2 1940-11-01 23:00:00 7200
# # 3 1940-12-30 22:00:00 3600
# # 5 1941-10-04 22:00:00 3600
# # 6 1942-05-03 01:00:00 7200
# # 7 1942-10-03 22:00:00 3600
# # 8 1980-12-31 23:00:00 3600
# # 9 1981-03-29 01:00:00 7200
# # ...
# # Note:
# # Important, the "TZ" environment variable must set
# # to "GMT" in your Windows Environment!
#
# # Set Timezone to GMT:
# myTZ = Sys.getenv("TZ")
# Sys.setenv(TZ = "GMT")
# if (FinCenter == "") FinCenter = "GMT"
#
# # Read the Rules:
# # Get IcalPath from .FirstLib
# file = paste(IcalPath, FinCenter, sep = "")
# zfile <- zip.file.extract(file, "Rdata.zip")
# ical = read.table(zfile, skip = 2)
#
# # GMT Offsets:
# hm = as.integer(ical[,6])
# sg = sign(hm)
# hm = abs(hm)
# h = floor(hm/100)
# hms.off = sg * ( floor(hm/100)*3600 + (hm - 100*h)*60 + 0 )
# hms.off
#
# # When have the rules changed?
# months.num = 1:12
# names(months.num) = c(
# "Jan", "Feb", "Mar", "Apr", "May", "Jun",
# "Jul", "Aug", "Sep", "Oct", "Nov", "Dec")
# Y = as.integer(ical[,4])
# m = as.integer(months.num[as.character(ical[,3])])
# d = as.integer(ical[,2])
# CCYYMMDD = as.character(Y*10000+100*m+d)
# hms = unlist(strsplit(as.character(ical[,5]), ":"))
# hms = matrix(as.integer(hms), byrow=TRUE, ncol=3)
# hms = 1000000 + 10000*hms[,1] + 100*hms[,2] + hms[,3]
# hhmmss = substr(as.character(hms), 2, 7)
# ruleChangesGMT = strptime(paste(CCYYMMDD, hhmmss), "%Y%m%d %H%M%S")
# attr(ruleChangesGMT, "tzone") <- "GMT"
#
# # Return Value:
# Sys.setenv(TZ = myTZ)
# data.frame(ruleChanges = as.character(ruleChangesGMT),
# offSet = hms.off) }
# }
# ## Instead:
# Match City:
fccity <- strsplit(FinCenter, "/")[[1]]
City <- fccity[length(fccity)]
fun <- match.fun(City)
# Return Value:
fun()
}
################################################################################
|