-
Notifications
You must be signed in to change notification settings - Fork 3
/
tz-brazil.rb
21 lines (17 loc) · 883 Bytes
/
tz-brazil.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#!/usr/bin/env ruby
# Encoding: UTF-8
# TZ Configuration for Brazil 2016.1.23
# Copyright (c) 2012 Renato Silva
# GNU GPLv2 licensed
# This program prints configuration of TZ environment variable for BRT
# timezone. BRT is the main timezone in Brazil, and corresponds to the
# official time at Brasília. This program uses a timezone database to
# automatically determine the end week for summer time period, which
# is variable in Brazil as of 2012. Despite being created for use with
# MinGW MSYS, this program is suitable for POSIX systems in general.
require 'rubygems'
require 'tzinfo'
current = TZInfo::Timezone.get('America/Sao_Paulo').current_period
dst_end = (current.dst? ? current.end_transition : current.start_transition).at.to_datetime
dst_end_week = (dst_end.day / 7) + (dst_end.day % 7 > 0 ? 1 : 0)
puts "export TZ=\"BRT+3BRST,M10.3.0/0,M2.#{dst_end_week}.0/0\""