Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8786793
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T21:43:41+00:00 2026-06-13T21:43:41+00:00

What’s the task? By project specification i need to calculate DST rules for specific

  • 0

What’s the task?
By project specification i need to calculate DST rules for specific time zone offsets. Rules cannot be applied via standard instruments like date_default_timezone_set() because we can’t rely on software configuration and can’t get it updated if some DST rules will be changed.

What i have?
In situations when DST switch date is on the last week and the switch day of the last week is on the next month i need to decrement the number of the last week. For now i have only one ugly solution:

 $week = 5;
 if (
     (1 + 7 * ($week - 1)) 
     + $start['day_of_week'] 
     - date('w', mktime(0, 0, 0, $start['month'], 1, date('Y', $start['timestamp']))) 
     > 
     date('t', $start['month'])) 
 {
     $week--;
 }

What am i looking for?
I’m looking for any ideas for a simplest solution for this, or links =)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T21:43:42+00:00Added an answer on June 13, 2026 at 9:43 pm

    You could use the system-wide timezone database and maintain custom updates to it.

    Official TZ database repository at IANA

    It is available as source files that you can modify when needed and recompile into binary files that can be used by the glibc time functions, and consequently by all programs that use those time functions. You might need to find a way to disable any automatic updates to that database, if your distro performs such updates, or you will lose your custom changes.

    I’m not certain if PHP actually follows the system-wide TZ database. The PECL timezonedb package seems to indicate that it is a separate recompiled version of the IANA database, so it might not observe changes in the system-wide database.

    If PHP disregards changes in the system-wide database, you could retrieve the zone offset by invoking any external program that uses the glibc timezone-aware time functions and that supports returning the timezone offset, e.g.:

    putenv('TZ=America/New_York');
    $offset = exec('date +%z');
    

    $offset will be in format ±HHMM, so some additional parsing will be required.

    You can also find the correct offset for specific timestamps, different from the current time:

    $unix_timestamp = 1350757594;
    $offset = exec('date +%z --date=@'.$unix_timestamp);
    

    Of course, proper filtering through escapeshellarg would be required if the timestamp comes from an untrusted source.

    UPDATE: Here’s a solution for a single DST ruleset; no external resources are used

    function calculate_offset($ts) {
        static $standard_offset = 2;    // = +2:00
        static $dst_offset      = 3;    // = +3:00
        static $dst_start       = 'last Sunday of March %d 1:00';
        static $dst_end         = 'last Sunday of October %d 1:00';
    
        date_default_timezone_set('UTC');
    
        $y = idate('Y', $ts);
        $start = strtotime(sprintf($dst_start, $y));
        $end = strtotime(sprintf($dst_end, $y));
    
        if ($start < $end) {
            // Northern hemisphere, DST starts earlier in the year than it ends
            $offset = ($ts >= $start && $ts < $end)? $dst_offset: $standard_offset;
        } else {
            // Southern hemisphere, DST ends earlier in the year than it starts
            $offset = ($ts >= $end && $ts < $start)? $standard_offset: $dst_offset;
        }
        $utc_time = strftime('%Y/%m/%d %H:%M:%S', $ts);
        $local_time = strftime('%Y/%m/%d %H:%M:%S', $ts + $offset * 60 * 60);
        printf("TS: %d; Offset: +%02d:00; UTC: %s; Local: %s\n", $ts, $offset, $utc_time, $local_time);
    }
    

    The example code uses the standard European DST rules and Eastern European Time offsets. You will need to find a way to express your DST start and end rules in the format understood by strtotime: Relative Formats. A %d in your DST start/end rule will be replaced by the year your timestamp falls in, so that weekday-in-month rules will find correct dates for the specific year. All calculations are done in UTC times, so your rules should refer to DST start/end times in UTC.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
In my XML file chapters tag has more chapter tag.i need to display chapters
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
Seemingly simple, but I cannot find anything relevant on the web. What is the
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I need a function that will clean a strings' special characters. I do NOT
I have thousands of HTML files to process using Groovy/Java and I need to
I need to clean up various Word 'smart' characters in user input, including but
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.