<p>Originally I am looking for a solution in Actionscript. The point of this question is the algorithm, which detects the exact Minute, when a clock has to switch the Daylight Saving Time. </p>

<p>So for example between the 25th and the 31th of October we have to check, if the actual date is a sunday, it is before or after 2 o'clock...</p>

[{'answer_id': 154765, 'author': 'Benno Richters', 'author_id': 3565, 'author_profile': 'https://Stackoverflow.com/users/3565', 'pm_score': 2, 'selected': False, 'text': '<p>There is no real algorithm for dealing with Daylight Saving Time. Basically every country can decide for themselves when -and if- DST starts and ends. The only thing we can do as developers is using some sort of table to look it up. Most computer languages integrate such a table in the language.</p>\n\n<p>In Java you could use the <code>inDaylightTime</code> method of the <a href="http://java.sun.com/javase/6/docs/api/java/util/TimeZone.html" rel="nofollow noreferrer">TimeZone</a> class. If you want to know the exact date and time when DST starts or ends in a certain year, I would recommend to use <a href="http://joda-time.sourceforge.net/" rel="nofollow noreferrer">Joda Time</a>. I can\'t see a clean way of finding this out using just the standard libraries.</p>\n\n<p>The following program is an example: (Note that it could give unexpected results if a certain time zone does not have DST for a certain year)</p>\n\n<pre><code>import org.joda.time.DateTime;\nimport org.joda.time.DateTimeZone;\n\npublic class App {\n    public static void main(String[] args) {\n        DateTimeZone dtz = DateTimeZone.forID("Europe/Amsterdam");\n\n        System.out.println(startDST(dtz, 2008));\n        System.out.println(endDST(dtz, 2008));\n    }\n\n    public static DateTime startDST(DateTimeZone zone, int year) {\n        return new DateTime(zone.nextTransition(new DateTime(year, 1, 1, 0, 0, 0, 0, zone).getMillis()));\n    }\n\n    public static DateTime endDST(DateTimeZone zone, int year) {\n        return new DateTime(zone.previousTransition(new DateTime(year + 1, 1, 1, 0, 0, 0, 0, zone).getMillis()));\n    }\n}\n</code></pre>\n'}, {'answer_id': 50499119, 'author': 'Basil Bourque', 'author_id': 642706, 'author_profile': 'https://Stackoverflow.com/users/642706', 'pm_score': 1, 'selected': False, 'text': '<p>The <a href="https://stackoverflow.com/a/154765/642706">Answer by Richters</a> is correct and should be accepted.</p>\n\n<p>As Richters noted, there is no logic to <a href="https://en.wikipedia.org/wiki/Daylight_saving_time" rel="nofollow noreferrer">Daylight Saving Time (DST)</a> or other anomalies. Politicians arbitrarily redefine the <a href="https://en.wikipedia.org/wiki/UTC_offset" rel="nofollow noreferrer">offset-from-UTC</a> used in their <a href="https://en.wikipedia.org/wiki/Time_zone" rel="nofollow noreferrer">time zones</a>. They make these changes often with little forewarning, or even no warning at all as <a href="http://www.bbc.com/news/world-asia-44010705" rel="nofollow noreferrer">North Korea did</a> a few weeks ago.</p>\n\n<h1>java.time</h1>\n\n<p>Here are some further thoughts, and example code using the modern <em>java.time</em> classes that succeeded the Joda-Time classes shown in his Answer.</p>\n\n<p>These changes are tracked in a list maintained by <a href="https://en.wikipedia.org/wiki/ICANN" rel="nofollow noreferrer">ICANN</a>, known as <a href="https://en.wikipedia.org/wiki/Tz_database" rel="nofollow noreferrer"><em>tzdata</em></a>, formerly known as the Olson Database. Your Java implementation, host operating system, and database system likely all have their own copies of this data which must be replaced as needed when changes are mode to zones you care about. There is no logic to these changes, so there is no way to predict the changes programmatically. Your code must call upon a fresh copy of <em>tzdata</em>.</p>\n\n<blockquote>\n  <p>So for example between the 25th and the 31th of October we have to check, if the actual date is a sunday, it is before or after 2 o\'clock...</p>\n</blockquote>\n\n<p>Actually, you need not determine the point of the cut-over. A good date-time library handles that for you automatically. </p>\n\n<p>Java has the best such library, the industry-leading <em>java.time</em> classes. When you ask for a time-of-day on a certain date in a certain region (time zone), if that time-of-day is no valid an adjustment is made automatically. Read the documentation for the <code>ZonedDateTime</code> to understand the algorithm used in that adjustment.</p>\n\n<pre><code>ZoneId z = ZoneId.of( "America/Montreal" );\nLocalDate ld = LocalDate.of( 2018 , Month.MARCH , 11 );  // 2018-03-11.\nLocalTime lt = LocalTime.of( 2 , 0 );  // 2 AM.\nZonedDateTime zdt = ZonedDateTime.of( ld , lt , z );\n</code></pre>\n\n<p>Notice the result is 3 AM rather than the 2 AM requested. There was no 2 AM on that date in that zone. So java.time adjusted to 3 AM as the clock “Springs ahead” an hour.</p>\n\n<blockquote>\n  <p>zdt.toString(): 2018-03-11T03:00-04:00[America/Montreal]</p>\n</blockquote>\n\n<p>If you feel the need to investigate the rules defined for a time zone, use the <a href="https://docs.oracle.com/javase/10/docs/api/java/time/zone/ZoneRules.html" rel="nofollow noreferrer"><code>ZoneRules</code></a> class.</p>\n\n<p>Get the amount of DST shift used in the present moment.</p>\n\n<pre><code>Duration d = z.getRules().getDaylightSavings\u200b( Instant.now() ) ;\n</code></pre>\n\n<p>Get the next planned change, represented as a <a href="https://docs.oracle.com/javase/10/docs/api/java/time/zone/ZoneOffsetTransition.html" rel="nofollow noreferrer"><code>ZoneOffsetTransition</code></a> object.</p>\n\n<pre><code>ZoneId z = ZoneId.of( "America/Montreal" );\nZoneOffsetTransition t = z.getRules().nextTransition( Instant.now() );\nString output = "For zone: " + z + ", on " + t.getDateTimeBefore() + " duration change: " + t.getDuration() + " to " + t.getDateTimeAfter();\n</code></pre>\n\n<blockquote>\n  <p>For zone: America/Montreal, on 2018-11-04T02:00 duration change: PT-1H to 2018-11-04T01:00</p>\n</blockquote>\n\n<p>Specify a <a href="https://en.wikipedia.org/wiki/List_of_tz_zones_by_name" rel="nofollow noreferrer">proper time zone name</a> in the format of <code>continent/region</code>, such as <a href="https://en.wikipedia.org/wiki/America/Montreal" rel="nofollow noreferrer"><code>America/Montreal</code></a>, <a href="https://en.wikipedia.org/wiki/Africa/Casablanca" rel="nofollow noreferrer"><code>Africa/Casablanca</code></a>, or <code>Pacific/Auckland</code>. Never use the 3-4 letter abbreviation such as <code>EST</code> or <code>IST</code> as they are <em>not</em> true time zones, not standardized, and not even unique(!). </p>\n\n<hr>\n\n<h1>About <em>java.time</em></h1>\n\n<p>The <a href="http://docs.oracle.com/javase/10/docs/api/java/time/package-summary.html" rel="nofollow noreferrer"><em>java.time</em></a> framework is built into Java 8 and later. These classes supplant the troublesome old <a href="https://en.wikipedia.org/wiki/Legacy_system" rel="nofollow noreferrer">legacy</a> date-time classes such as <a href="https://docs.oracle.com/javase/10/docs/api/java/util/Date.html" rel="nofollow noreferrer"><code>java.util.Date</code></a>, <a href="https://docs.oracle.com/javase/10/docs/api/java/util/Calendar.html" rel="nofollow noreferrer"><code>Calendar</code></a>, &amp; <a href="http://docs.oracle.com/javase/10/docs/api/java/text/SimpleDateFormat.html" rel="nofollow noreferrer"><code>SimpleDateFormat</code></a>.</p>\n\n<p>The <a href="http://www.joda.org/joda-time/" rel="nofollow noreferrer"><em>Joda-Time</em></a> project, now in <a href="https://en.wikipedia.org/wiki/Maintenance_mode" rel="nofollow noreferrer">maintenance mode</a>, advises migration to the <a href="http://docs.oracle.com/javase/10/docs/api/java/time/package-summary.html" rel="nofollow noreferrer">java.time</a> classes.</p>\n\n<p>To learn more, see the <a href="http://docs.oracle.com/javase/tutorial/datetime/TOC.html" rel="nofollow noreferrer"><em>Oracle Tutorial</em></a>. And search Stack Overflow for many examples and explanations. Specification is <a href="https://jcp.org/en/jsr/detail?id=310" rel="nofollow noreferrer">JSR 310</a>.</p>\n\n<p>You may exchange <em>java.time</em> objects directly with your database. Use a <a href="https://en.wikipedia.org/wiki/JDBC_driver" rel="nofollow noreferrer">JDBC driver</a> compliant with <a href="http://openjdk.java.net/jeps/170" rel="nofollow noreferrer">JDBC 4.2</a> or later. No need for strings, no need for <code>java.sql.*</code> classes.</p>\n\n<p>Where to obtain the java.time classes? </p>\n\n<ul>\n<li><a href="https://en.wikipedia.org/wiki/Java_version_history#Java_SE_8" rel="nofollow noreferrer"><strong>Java SE 8</strong></a>, <a href="https://en.wikipedia.org/wiki/Java_version_history#Java_SE_9" rel="nofollow noreferrer"><strong>Java SE 9</strong></a>, <a href="https://en.wikipedia.org/wiki/Java_version_history#Java_SE_10" rel="nofollow noreferrer"><strong>Java SE 10</strong></a>, and later\n\n<ul>\n<li>Built-in. </li>\n<li>Part of the standard Java API with a bundled implementation.</li>\n<li>Java 9 adds some minor features and fixes.</li>\n</ul></li>\n<li><a href="https://en.wikipedia.org/wiki/Java_version_history#Java_SE_6" rel="nofollow noreferrer"><strong>Java SE 6</strong></a> and <a href="https://en.wikipedia.org/wiki/Java_version_history#Java_SE_7" rel="nofollow noreferrer"><strong>Java SE 7</strong></a>\n\n<ul>\n<li>Much of the java.time functionality is back-ported to Java 6 &amp; 7 in <a href="http://www.threeten.org/threetenbp/" rel="nofollow noreferrer"><strong><em>ThreeTen-Backport</em></strong></a>.</li>\n</ul></li>\n<li><a href="https://en.wikipedia.org/wiki/Android_(operating_system)" rel="nofollow noreferrer"><strong>Android</strong></a>\n\n<ul>\n<li>Later versions of Android bundle implementations of the java.time classes.</li>\n<li>For earlier Android (&lt;26), the <a href="https://github.com/JakeWharton/ThreeTenABP" rel="nofollow noreferrer"><strong><em>ThreeTenABP</em></strong></a> project adapts <a href="http://www.threeten.org/threetenbp/" rel="nofollow noreferrer"><strong><em>ThreeTen-Backport</em></strong></a> (mentioned above). See <a href="http://stackoverflow.com/q/38922754/642706"><em>How to use ThreeTenABP…</em></a>.</li>\n</ul></li>\n</ul>\n\n<p>The <a href="http://www.threeten.org/threeten-extra/" rel="nofollow noreferrer"><strong>ThreeTen-Extra</strong></a> project extends java.time with additional classes. This project is a proving ground for possible future additions to java.time. You may find some useful classes here such as <a href="http://www.threeten.org/threeten-extra/apidocs/org/threeten/extra/Interval.html" rel="nofollow noreferrer"><code>Interval</code></a>, <a href="http://www.threeten.org/threeten-extra/apidocs/org/threeten/extra/YearWeek.html" rel="nofollow noreferrer"><code>YearWeek</code></a>, <a href="http://www.threeten.org/threeten-extra/apidocs/org/threeten/extra/YearQuarter.html" rel="nofollow noreferrer"><code>YearQuarter</code></a>, and <a href="http://www.threeten.org/threeten-extra/apidocs/index.html" rel="nofollow noreferrer">more</a>.</p>\n'}]
['https://Stackoverflow.com/questions/70964', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/-1/']